David McGaffin
2005-Jul-13 20:16 UTC
can''t figure out how to add option tags to a select with ajax.
There must be something obvious that I''m missing, but when I try to add an option tag to a select tag, I end up with this: <select id="grant_source_id" name="grant[source_id]"> newItemThatShouldBeAnOption <option value="1">First Option</option> <option value="2">Second Option</option> </select The added item appears in the list, but it can''t be selected, since it is just text. The new source is added to the database, but the partial always returns just the source name with no html around it. I can''t figure out how this is happening. I have added debug statements to ensure that the partial is being called, and it is... Any help is appreciated. Here is my controller for the ajax call: def create_ajax @source = Source.new(@params[:source]) if @source.save render(:partial => "source_option", :object => @source) end end And here is my partial, _source_option.rhtml: <option value="<%= source_option.id %>"><%source_option.organization %></option> And, finally, here is the relevant view code that calls the controller: <%= select_tag("grant[source_id]", options_from_collection_for_select(@sources, "id", organization", @grant.source_id), :id => "grant_source_id") %> ... <%= form_remote_tag :url => {:controller => "source", :action => "create_ajax"}, :update => "grant_source_id", :position => :top, :complete => "new Effect.Fade(''newsource'')" %> - david
Michael Schuerig
2005-Jul-13 21:42 UTC
Re: can''t figure out how to add option tags to a select with ajax.
On Wednesday 13 July 2005 22:16, David McGaffin wrote:> There must be something obvious that I''m missing, but when I try to > add an option tag to a select tag, I end up with this: > > <select id="grant_source_id" name="grant[source_id]"> > newItemThatShouldBeAnOption > <option value="1">First Option</option> > <option value="2">Second Option</option> > </selectFirefox? Doesn''t work -- you have to update the entire select element. I seem to remember that this has been fixed in an upcoming version, but I may well be confusing things here. Michael -- Michael Schuerig This is not a false alarm mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org This is not a test http://www.schuerig.de/michael/ --Rush, Red Tide
David McGaffin
2005-Jul-14 00:25 UTC
Re: Re: can''t figure out how to add option tags to a select with ajax.
Yes, firefox indeed. I didn''t know about the bug. Thanks for stopping my headscratching. - david On 7/13/05, Michael Schuerig <michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org> wrote:> On Wednesday 13 July 2005 22:16, David McGaffin wrote: > > There must be something obvious that I''m missing, but when I try to > > add an option tag to a select tag, I end up with this: > > > > <select id="grant_source_id" name="grant[source_id]"> > > newItemThatShouldBeAnOption > > <option value="1">First Option</option> > > <option value="2">Second Option</option> > > </select > > Firefox? Doesn''t work -- you have to update the entire select element. > > I seem to remember that this has been fixed in an upcoming version, but > I may well be confusing things here. > > Michael > > -- > Michael Schuerig This is not a false alarm > mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org This is not a test > http://www.schuerig.de/michael/ --Rush, Red Tide > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >