Removing form observers

Hi,

I’m developing a Rails app which uses dynamic forms. To implement
these, I’ve used AJAX and Rails’s built-in form observers.
Unfortunately, I’m having a problem.

This is how the form starts:

  • Country select box [OBSERVED] (Republic of Ireland selected)
  • County select box [OBSERVED] (none selected, list of Republic of
    Irish counties in the drop down)

when a user selects a county, the browser requests the rest of the form:

  • Country select box [OBSERVED] (Republic of Ireland selected)
  • County select box [OBSERVED] (none selected, list of Republic of
    Irish counties in the drop down)
  • Town select box (none selected)
  • Address line 1-3 (text inputs)

This works fine. The problem occurs when a different country is
selected. This reloads the rest of the form (including the observed
county select box if the country is Northern Ireland). When this
happens, the county select does not work. It does not trigger any AJAX
calls.

I believe this is caused by an event observer observing a replaced
element.

What I’d like to be able to do is remove the form observer for the
county field when the country is changed, and put it back in when the
AJAX work is all done.

This would allow me to have a default country (kind-of handy as 99% of
addresses stored will be in the Republic of Ireland) and have the form
update accordingly.

Any ideas on how one would go around doing this? Documentation for
Prototype is sparse to say the least! :slight_smile:

Dave


Site: http://antidis.com/

David B. wrote:

This works fine. The problem occurs when a different country is
selected. This reloads the rest of the form (including the observed
county select box if the country is Northern Ireland). When this
happens, the county select does not work. It does not trigger any AJAX
calls.

I believe this is caused by an event observer observing a replaced element.

Yes, put each observe_field script section in the same div as the
select it is observing, and always render and remove them together.


We develop, watch us RoR, in numbers too big to ignore.

Thanks Mark, I’ll try that out.

Dave

On 2/22/06, Mark Reginald J. [email protected] wrote:

Yes, put each observe_field script section in the same div as the
select it is observing, and always render and remove them together.


We develop, watch us RoR, in numbers too big to ignore.


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


Site: http://antidis.com/