Archive for the ‘prototype’ category

observe_form values lost in the ether

September 21st, 2007

When using observe_form, there’s a sneaky nastyness. (Rails 1.2.3) It’s a bit inconsistent. Hopefully this will clear it up.

With no ‘update’ or ‘with’ parameter then the values aren’t passed:
new Form.Observer('theform', 1, function(element, value) {new Ajax.Request('/controller/action', {asynchronous:true, evalScripts:true})})

Surely this is a bug? It should include ‘parameters:value’.

Using – :with => ‘values’
new Form.Observer('theform', 1, function(element, value) {new Ajax.Request('/controller/action', {asynchronous:true, evalScripts:true, parameters:'values=' + value})})

Getting there but still doesn’t quite work. Try it and you’ll see why.

Using – :update => {}, and no ‘with’
new Form.Observer('theform', 1, function(element, value) {new Ajax.Updater({}, '/controller/action', {asynchronous:true, evalScripts:true, parameters:value})})

This now works as it’s changed to use the Ajax.Updater passing the parameters as we wanted in the first attempt.
I hope his saves someone some time :-)

Credits due here for the empty hash fix: http://wiki.rubyonrails.org/rails/pages/observe_form+-+Passing+Parameters

Events missed by the almighty Prototype!

September 19th, 2007

This one’s worth knowing: http://dev.rubyonrails.org/ticket/7895

The problem I encountered was that EventObserver (Prototype) or observe_field (RJS equivalent) only fire the first time on radio buttons. It would be nice to see if Prototype 1.6.0 will fix this, but alas, I’ve not got time for such luxuries right now. Anyone else tried?