Forum: Ruby on Rails observe_field using :on => select not working

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
stephen O'D (Guest)
on 2007-07-20 19:07
(Received via mailing list)
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 T. (Guest)
on 2007-07-20 21:13
(Received via mailing list)
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 <removed_email_address@domain.invalid> 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.
stephen O'D (Guest)
on 2007-07-20 23:40
(Received via mailing list)
On Jul 20, 6:13 pm, "Ramon Miguel M. Tayag" 
<removed_email_address@domain.invalid>
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!
stephen O'D (Guest)
on 2007-07-21 17:11
(Received via mailing list)
On Jul 20, 6:13 pm, "Ramon Miguel M. Tayag" 
<removed_email_address@domain.invalid>
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.
This topic is locked and can not be replied to.