Radio button observe field only triggers once

Hi,

If i add field observers to radio button fields they trigger once but
then nothing after that. I have multiple fields in a form that i need
to know if one of them changes and which spedific field. Below is an
example of two foelds i tested and they trigger once with the alert but
then nothing after that. I also tried individual observers for each
field test_yes and test_no but with the same issue.

<%= radio_button_tag ‘test’, “yes” %>
<%= radio_button_tag ‘test’, “no” %>

<%= observe_field(‘test’,
:on => ‘click’,
:function => “alert(‘Element Yes changed’)”%>

Does anyone know why or experienced something like this before?

JB

If I remember correctly, I think you’ll need an id on each radio
button and need to observe each radio button individually. The
‘grouping’ of the radio buttons into a single field value that’s
posted back does not replace the fact that it’s actually a collection
of individual html elements on the form.

On May 16, 4:07 pm, John B. [email protected]

AndyV wrote:

If I remember correctly, I think you’ll need an id on each radio
button and need to observe each radio button individually. The
‘grouping’ of the radio buttons into a single field value that’s
posted back does not replace the fact that it’s actually a collection
of individual html elements on the form.

On May 16, 4:07 pm, John B. [email protected]

Ye ive tried adding an observer to each individual radio button but the
same thing happens.

<%= observe_field(‘test_yes’,
:on => ‘click’,
:function => “alert(‘Element Yes changed’)”%>

<%= observe_field(‘test_no’,
:on => ‘click’,
:function => “alert(‘Element Yes changed’)”%>

Im just going to have to post the whole form back and find out which one
is set to 1 and do it that way.

I have the same error. If anybody meanwhile has a solution, I would be
happy if it would be posted here.

Thanks!
der Flo

You might want to try observe_form,
http://wiki.rubyonrails.org/rails/pages/observe_form+-+Passing+Parameters

Justin To wrote:

You might want to try observe_form,
http://wiki.rubyonrails.org/rails/pages/observe_form+-+Passing+Parameters

Yes, observe_form works. Thanks for this hint.
But I’m nevertheless interested in the reason why observe_field is not
working as expected.

Again, thanks Justin

Florian Dütsch wrote:

But I’m nevertheless interested in the reason why observe_field is not
working as expected.

It actually is a big bug for rails:
http://dev.rubyonrails.org/ticket/7895

We all suffer from it, and work-arounds are very tedious

Ok, thanks. I’ll check out the patch provided in this ticket.