# Radio button observe field only triggers once

**URL:** <https://www.ruby-forum.com/t/radio-button-observe-field-only-triggers-once/137851>\
**Category:** Rails\
**Created:** [May 16, 2008, 10:07pm UTC](https://www.ruby-forum.com/t/radio-button-observe-field-only-triggers-once/137851 "2008-05-16T22:07:36Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [May 16, 2008, 10:07pm UTC](https://www.ruby-forum.com/t/radio-button-observe-field-only-triggers-once/137851/1 "2008-05-16T22:07:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [May 17, 2008, 10:16pm UTC](https://www.ruby-forum.com/t/radio-button-observe-field-only-triggers-once/137851/2 "2008-05-17T22:16:16Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [May 18, 2008, 12:19pm UTC](https://www.ruby-forum.com/t/radio-button-observe-field-only-triggers-once/137851/3 "2008-05-18T12:19:50Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

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.

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [August 1, 2008, 4:56pm UTC](https://www.ruby-forum.com/t/radio-button-observe-field-only-triggers-once/137851/4 "2008-08-01T16:56:11Z")

</div>

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

Thanks!  
der Flo

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [August 2, 2008, 12:22am UTC](https://www.ruby-forum.com/t/radio-button-observe-field-only-triggers-once/137851/5 "2008-08-02T00:22:28Z")

</div>

You might want to try observe\_form,  
[http://wiki.rubyonrails.org/rails/pages/observe\_form+-+Passing+Parameters](http://wiki.rubyonrails.org/rails/pages/observe_form+-+Passing+Parameters)

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [August 4, 2008, 2:41pm UTC](https://www.ruby-forum.com/t/radio-button-observe-field-only-triggers-once/137851/6 "2008-08-04T14:41:27Z")

</div>

Justin To wrote:

> You might want to try observe\_form,  
> [http://wiki.rubyonrails.org/rails/pages/observe\_form+-+Passing+Parameters](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

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [August 6, 2008, 9:37pm UTC](https://www.ruby-forum.com/t/radio-button-observe-field-only-triggers-once/137851/7 "2008-08-06T21:37:17Z")

</div>

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](http://dev.rubyonrails.org/ticket/7895)

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

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [August 7, 2008, 11:52am UTC](https://www.ruby-forum.com/t/radio-button-observe-field-only-triggers-once/137851/8 "2008-08-07T11:52:59Z")

</div>

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