Observe_field + enable/disable field

Hello,

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…)

Thanks,
Karine D.

form partial:

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

Note
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:

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