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!
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”) ) }
) %>
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 [email protected] wrote:
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 T.
On Jul 20, 6:13 pm, “Ramon Miguel M. Tayag” [email protected]
wrote:
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!
On Jul 20, 6:13 pm, “Ramon Miguel M. Tayag” [email protected]
wrote:
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.