Short version:
I have a radio_button group of two. If one is clicked another pair of
radio buttons is added, if the other is clicked it is removed.
observe_form does not work for elements added after initial page load.
observe_field does not work for radio_buttons except on the first
'click'
It was suggested that I stop observe_field before changes are made to
the form then restart it.
With much searching I found a Event.stopObserving method, but I'm not
certain how to apply this to my observe_form observer.
>From the source:
new Form.EventObserver('process_call_form', function(element, value)
{new Ajax.Request('/rails/assistant/add_element', {asynchronous:true,
evalScripts:true, parameters:'Form.serialize(process_call_form)=' +
value})})
>From this I did:
function = "function(element, value) {new
Ajax.Request('/rails/assistant/add_element', {asynchronous:true,
evalScripts:true, parameters:'Form.serialize(process_call_form)=' +
value})}"
page << "Event.stopObserving('process_call_form', 'change',
#{function})"
This doesn't throw an error, but it doesn't stop or "reset" the
observer as far as I can tell either. new element are still unobserved
and old elements still are.
I tried using 'click' instead of 'change' as well since the api docs
indicate that the default :on => option varies from buttons to other
elements.
var handle = Event.observe(element,'click',myFunc);
Event.stopObserving(element,'click',handle);
From what I can see in the source of the parent class
Abstract.EventObserver() there is no returning or caching of the
Event.observe() handles.
Perhaps this is a limitation or am I missing something?
--Ken