I can’t find a way to do what I’m trying so maybe someone can throw something at me.

The idea is if an option is not in a select list, the user can click a link next to the list ‘not there?’ and this will open uop a text field box below. The user then enters the missing option, hits enter and the select list will update and have the new entry already selected.

I can use remote_form_tag to get to send the text_field without refreshing the page but I can’t find an option as with text_field_with_auto_complete’s :after_update_element. I want to fire another Ajax request to repopulate the select list.

I may already have seen the solution in my searching but I now can’t see the wood for the trees.



Perhaps you can add a link_to_remote, either in the section or surrounding it, to add an extra option then update the select list.

The Rails Cookbook has a section on using ajax to add DOM Elements to a page

And there is this :http://api.rubyonrails.org/classes/ActionView/ Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods.html

Yeah, thanks for that. I went away yesterday and when I came back to it, I arrived at the same solution.

Are you an expert with RJS? If so, I have another question. I have a select drop down list that will now be added to dynamically using RJS. But upon completion of the RJS request, all of my observer fields die (stop observing) unless I physically refresh the page.

Any idea what I need to do to rectify that?

You need to re-add the observers in your RJS call. If you have an observer on an element with ID foo & you replace that element (page[:foo].reload), the observer goes with it. However, depending on how your observer is setup adding to the element ie another li or a subnode, can limit the need for resetting the observer.

JQuery has a “live” feature that basically does this for you, albeit with a small performance overhead.


Good timing, just came to check my replies.

Thanks for the heads up on that, I’ll give it a go. I hate frontend development!! Whatever was wrong with static HTML?!! :wink: