Is there a known bug with observe_field using the :on parameter? I want to observe a select list, and only update a child select list after someone has made a selection, so I want to use the onSelect event. However no matter what I set as the value of :on it still behaves as if it is set to change (the default). I came across this http://joshhuckabee.com/taxonomy/term/5 which implies there is a bug - I even change my prototype.js to match his changes, but it still is not behaving as I would have expected. I have used onSelect before in select lists, and it definitely only fires when you actually make the selection, so I am very confused! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ramon Miguel M. Tayag
2007-Jul-20 17:13 UTC
Re: observe_field using :on => select not working
I was frustrated with this as well; there isn''t good documentation online. Or, if there is, I couldn''t easily find it. I got this information through bugging a bunch of people in IRC. It might be better to do it this way: ---------------------------------- <%= collection_select("rates_calc", "origin_id", @locations, :id, :name, {}, {:onchange => remote_function(:url => {:action => "show_origin_sublocations"}, :with => encodeURI_selection("rates_calc", "origin_id", "value") ) } ) %></p> ---------------------------------- where is a helper: ---------------------------------- def encodeURI_selection(object, method, value) return "''#{method}='' + encodeURIComponent(" + get_element_by_method(object, method, value) + ")" end def get_element_by_method(object, method, value) return "document.getElementById(''#{object}_#{method}'').#{value}" end ---------------------------------- basically, show_origin_sublocations will call an RJS which will have your JS code to do whatever you want. On 7/20/07, stephen O''D <stephen.odonnell-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Is there a known bug with observe_field using the :on parameter? > > I want to observe a select list, and only update a child select list > after someone has made a selection, so I want to use the onSelect > event. However no matter what I set as the value of :on it still > behaves as if it is set to change (the default). > > I came across this http://joshhuckabee.com/taxonomy/term/5 which > implies there is a bug - I even change my prototype.js to match his > changes, but it still is not behaving as I would have expected. > > I have used onSelect before in select lists, and it definitely only > fires when you actually make the selection, so I am very confused! > > > > >-- Ramon Tayag --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jul 20, 6:13 pm, "Ramon Miguel M. Tayag" <ramon.ta...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I was frustrated with this as well; there isn''t good documentation > online. Or, if there is, I couldn''t easily find it. I got this > information through bugging a bunch of people in IRC. > > It might be better to do it this way: > ---------------------------------- > <%= collection_select("rates_calc", "origin_id", @locations, :id, :name, {}, > {:onchange => remote_function(:url => {:action => "show_origin_sublocations"}, > :with => encodeURI_selection("rates_calc", "origin_id", "value") ) } ) %></p> > ---------------------------------- > > where is a helper: > ---------------------------------- > def encodeURI_selection(object, method, value) > return "''#{method}='' + encodeURIComponent(" + > get_element_by_method(object, method, value) + ")" > end > > def get_element_by_method(object, method, value) > return "document.getElementById(''#{object}_#{method}'').#{value}" > end > ---------------------------------- > > basically, show_origin_sublocations will call an RJS which will have > your JS code to do whatever you want.Interesting - I will give that a go tomorrow and hopefully it works out better. So frustrating with the observe method, as its so simple! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jul 20, 6:13 pm, "Ramon Miguel M. Tayag" <ramon.ta...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I was frustrated with this as well; there isn''t good documentation > online. Or, if there is, I couldn''t easily find it. I got this > information through bugging a bunch of people in IRC. > > It might be better to do it this way: > ---------------------------------- > <%= collection_select("rates_calc", "origin_id", @locations, :id, :name, {}, > {:onchange => remote_function(:url => {:action => "show_origin_sublocations"}, > :with => encodeURI_selection("rates_calc", "origin_id", "value") ) } ) %></p> > ---------------------------------- > > where is a helper: > ---------------------------------- > def encodeURI_selection(object, method, value) > return "''#{method}='' + encodeURIComponent(" + > get_element_by_method(object, method, value) + ")" > end > > def get_element_by_method(object, method, value) > return "document.getElementById(''#{object}_#{method}'').#{value}" > end > ---------------------------------- > > basically, show_origin_sublocations will call an RJS which will have > your JS code to do whatever you want. >I got the observe_file method working - upon re-reading the docs, it seemed that not setting the frequency parameter was the way to achieve what I wanted, and that onchange was infact the correct event to check for when using a select list. Cheers, Stephen. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---