Observe_field + enable/disable field


I have a form with two observe_field, one on a select tag, the other on
a checkbox. The form also has a text field. By default, the checkbox
is not checked, the text field is disabled, and changing the select
value will change the text field value. If the user checks the box,
the text field is enabled, and the select doesn’t change it anymore.
If unchecked, the text field is disabled again and the default
behavior comes back.

So far, I have the text field value right, but not its
enabling/disabling. I guess that’s just some simple Ajax I’m missing on
the :complete option, but I can’t find the right way to do it as it
depends on the checkbox state. Or should that go in the controller?
(where I put my #TODO lines…)

Karine D.

form partial:

<%= select('book', 'collection_id', Collection.find(:all).collect {|c| [c.name, c.id]}) %>

Give another note than the collection's one

<%= render :partial => 'note' %>

<%= observe_field ‘book_collection_id’,
:update => “ajaxWrapper”,
:with => “‘collection_id=’ + encodeURIComponent(value) +
‘&overwrite_note=’ + escape($(‘book_overwrite_note’).checked)”,
:url => {:controller => “user”, :action => ‘note’} %>
<%= observe_field ‘book_overwrite_note’,
:update => “ajaxWrapper”,
:with => “‘overwrite_note=’ + encodeURIComponent(value) +
‘&collection_id=’ + escape($(‘book_collection_id’).value)”,
:url => {:controller => “user”, :action => ‘note’} %>

note partial:

def note
if (params[:overwrite_note] == “on” || params[:overwrite_note] ==
#TODO: enable book_note
@url_landing = Collection.find(params[:collection_id]).note
#TODO: disable book_note
render :partial => ‘note’, :layout => false