Andy Koch schrieb:
Hello,
I'm having trouble with observe_field and radio buttons. The issue is
the observe_field action only fires the first time, subsequent clicks on
radio buttons do nothing.
I've seen others post on this issue, but have not found any solutions.
CODE:
from view...
<label><%= radio_button_tag('types', 'p5p', (params[:dbinfo] ||= true))
%>P5P</label>
<label><%= radio_button_tag('types', 'p5i', false) %>P5I</label>
<%= observe_field(:types_p5p,
:udpate => 'categories',
:url => {:action => 'update_module_categories'},
:with => "'types=' + encodeURIComponent(value)",
:on => 'click' ) %>
<%= observe_field(:types_p5i,
:udpate => 'categories',
:url => {:action => 'update_module_categories'},
:with => "'types=' + encodeURIComponent(value)",
:on => 'click' ) %>
###############
This works the first time I click one of the radios, but never again.
Any ideas?
regards,
Andy Koch
>
In proper fashion I've solved my own problem. To save the next person
from following yet another fruitless thread I'll post it. However, this
comes with a caveat that I don't think this is a "best practices"
solution. It does work, nonetheless.
Instead of using observe_field, which I'm concluding does not work
properly with radio buttons; till someone tells me otherwise, I've
embedded the AJAX call into the radio.
Code being better than talk:
<label><%= radio_button_tag('types', 'p5p', (params[:dbinfo] ||= true),
{:onclick => "{new
Ajax.Updater('categories','/public/update_module_categories',
{asynchronous:true, evalScripts:true, parameters:'types=' +
encodeURIComponent(value)})}"}) %>P5P</label>
<label><%= radio_button_tag('types', 'p5i', false, {:onclick => "{new
Ajax.Updater('categories','/public/update_module_categories',
{asynchronous:true, evalScripts:true, parameters:'types=' +
encodeURIComponent(value)})}"}) %>P5I</label>
...............
Thus, I first generated the AJAX code via the observe_field method.
Then I copied out the relevant portions from the HTML source code and
pasted into the 'onclick' option of the radio button. Then deleted the
observe_field from the rhtml as it was now dead code.
It may not be pretty, but I can move to the next problem.
regards,
/ak