Select in partial not behaving

I have this select in a form: <%= select('contact', 'id', @contacts, {:prompt => 'Select Contact'} , { :onchange => remote_function(:url => { :controller => 'contacts', :action => "ajaxshowcontact", :id => @mop.id}, :with => "'contactid=' + this.value" ) } ) %>

The prompt works in the form but when I do a replace_html on it I get everything but the prompt. Any ideas?

Me wrote:

I have this select in a form: <%= select('contact', 'id', @contacts, {:prompt => 'Select Contact'} , { :onchange => remote_function(:url => { :controller => 'contacts', :action => "ajaxshowcontact", :id => @mop.id}, :with => "'contactid=' + this.value" ) } ) %>

The prompt works in the form but when I do a replace_html on it I get everything but the prompt.

Post the replace_html code?

Next, put only that <%= select %> thing into a partial (yes tiny otherwise useless partials are a Best Practice), then do rjs.replace_html :my_div, :partial => 'my_partial'. (I call "rjs" the variable everyone else calls "page", because the interthing has too many "page" variables all over it!)

You could also see about putting the :url into a named route. Just about anything in Rails that's "named" is a best practice, too!

Ok, that select I put is the only thing in the partial. Here is the rjs: page[:contact_list].replace_html :partial => ‘updateContactList’, :locals => { :contact => @contact }

Hmm, hope you can post up more code, even from your controller as well.

I think that instead of replacing the entire select tag, you can simply replace its contents. Firstly, give the select tag an id so that in your RJS, you can replace_html with options_for_select or whatever function you might want to use.

OK, I used the ID of the select and did a replace:

RJS: page[:showcontact].hide page[:contactlist].show page.insert_html :bottom,‘contactlist’, :partial => ‘ajaxAddToMop’, :locals => {:contact => @contact } page[:contact_id].replace :partial => “updateContactList”, :locals => {:contacts => @contacts, :mop => @mop }

Partial:

<%= select(‘contact’, ‘id’, @contacts, {:prompt => ‘Select Contact’} ,{ :onchange => remote_function(:url => { :controller => ‘contacts’, :action => “ajaxshowcontact”, :id => @mop.id}, :with => “‘contactid=’ + this.value” ) } ) %>

No change. Prompt is still not showing up. Data is there jsut not he prompt. I need the prompt as I use an ajax on change so the user can view/edit/update the user info if necessary inside the form. the controller code basically is updating the contact lsit.

1.Gets all contacts. 2. gets all contacts associated with the form 3. subtracts the two and givesme an array with the contacts not associated woit the form. 4. As I add users to the form I make the association to the form. This way I can update the list easier than keeping track of an array.

Here is the controller code, no real significance.

def ajaxAddToMop @contact = Contact.find(params[:contact][:id], :include => [:company]) @mop = Mop.find(params[:id]) @mop.contacts << @contact a = Contact.all.collect{|p| [ p.id ] } b = @mop.contacts.all.collect{|p| [ p.id ] } c = a-b ar = Array.new c.each{|arr| arr.each{|p| ar << p } }

    @contacts = Contact.find(:all, :conditions => ["id IN (?)", ar]).collect {|p| [ [p.name](http://p.name), [p.id](http://p.id) ] }

end

Ok this is weird, I have full CRUD working for my contacts table all doing ajax inline in my form. the odd one is that my delete funtion uses the same partial as the one above and when I do the rjs for the update on the select it DOES give me the "Prompt" to select User. Delete is the only one that the prompt actually comes back on. Same partial used on all of the updates to the contact select.

Not able to understand the flow of control. What is mop? Could you explain a bit further? This is interesting..

Well it is a telecom thing. If you perform maintenance on equipment then you need a form explaining what to do and how to do it.

Anyway, the partial gives me a “prompt” if I do a delete or if I remove the contact from the form I also do a replace like on an New contact and it does give me a prompt. If I do a “New” contact or “edit” I do not get a “prompt” in the select. all CRUD operations use the same partial to update the select, doing ajax inline with the form.

I meant the flow of control in the code. From the view to the controller action, to the RJS and back to the view. I dont see a call to ajaxAddToMop. What are the names of the files with the RJS and the select_box?

if I do a delete or if I remove the contact from the form I also do a replace like on an New contact and it does give me a prompt. If I do a "New" contact or "edit" I do not get a "prompt" in the select.

I personally cant understand that.

Ok, you asked what a mop was.

ajaxAddtoMop just makes the association between the contact and form then updates the select removing the user from the select box. I have quite a few rjs and partials to make the full CRUD operations working ajax wise inline in the form. I can go offline if you really want to know all of the files being used, kinda lengthy here.

The same partial is used between all actions doing a replace :partial. Just odd that only a couple of the functions give me the prompt. Basically it is really just a contact to form relationship. I may be using this same thing down the road I am sure. All of the new,edit,update,deletes of users are right in the form. Kinda cool really.

Sure.. lets take this outside! :wink:

It'll help if you send me the code with the flow for one action that works and one that doesnt. no promises :).