Forum: Ruby on Rails Removing form observers

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
967f758fa9de78e7fe8425469f7a7acc?d=identicon&s=25 David Barrett (Guest)
on 2006-02-22 20:33
(Received via mailing list)
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! :)

Dave

--
Site: http://antidis.com/
C64e63b70be7dfed8b0742540b8b27e5?d=identicon&s=25 Mark Reginald James (Guest)
on 2006-02-22 22:17
(Received via mailing list)
David Barrett 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.
967f758fa9de78e7fe8425469f7a7acc?d=identicon&s=25 David Barrett (Guest)
on 2006-02-23 16:56
(Received via mailing list)
Thanks Mark, I'll try that out.

Dave

On 2/22/06, Mark Reginald James <mrj@bigpond.net.au> 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
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
Site: http://antidis.com/
This topic is locked and can not be replied to.