observe_field

I have been trying to pass a collection_select parameter and a text field parameter to observe_field so that it watches both the parameters simultaneously.

but what i can see is , when i select some value from drop down and dont write anything in text field its giving correct results.parameters are also correct passed, but just after that if i write something in text field that value also get passed as collection_select parameter(labtid in my case) my view code is:

<form name="sform" id="myform" action="" style="display:inline;"> <br/>

<label for="dev_name">Filter on Device Name : </label> <%= text_field_tag("query", params['query'], :size => 10 )%>

<label>Lab : </label> <%= collection_select(:labt, :labtid,                          @labs, :id, :name,:prompt => "Select a Lab") %>

</form> <%= image_tag("spinner.gif",               :align => "absmiddle",               :border => 0,               :id => "spinner",               :style =>"display: none;" ) %> </p> <%= javascript_include_tag :defaults %>

<%= observe_field 'query', :frequency => 2,          :update => "table",          :before => "Element.show('spinner')",          :success => "Element.hide('spinner')",          :url => {:action => 'trial_location1'},          :with => "'labtid=' + value+'&query='+escape($('query').value)" %> <%= observe_field 'labt_labtid', :frequency => 2,          :update => "table",          :before => "Element.show('spinner')",          :success => "Element.hide('spinner')",          :url => {:action => 'trial_location1'},                   :with => "'labtid=' + value+'&query='+escape($('query').value)"

       %>

<div id="table"> <%= render :partial => "devices_list" %> </div>

i believe the problem lies with :with parameter. Can someone suggest me the problem? Thanking in advance!!

I have been trying to pass a collection_select parameter and a text
field parameter to observe_field so that it watches both the parameters simultaneously.

but what i can see is , when i select some value from drop down and
dont write anything in text field its giving correct results.parameters
are also correct passed, but just after that if i write something in text
field that value also get passed as collection_select parameter(labtid in my
case) my view code is:

<%= observe_field 'query', :frequency => 2,         :update => "table",         :before => "Element.show('spinner')",         :success => "Element.hide('spinner')",         :url => {:action => 'trial_location1'},         :with => "'labtid=' + value+'&query='+escape($ ('query').value)" %>

In the context of an observe_field, value is the value of the observed
field (so $('query').value in this case, and $('labt_labtid') in the
other, so you need to swap things around in the above observe_form
(the other one is fine) Might observe_form not be less hassle in this case ?

Fred

u mean it should be like this ? :with => “‘labt_labtid=’ + value+‘&query=’+escape($(‘query’).value)”

u mean it should be like this ? :with => "'labt_labtid=' + value+'&query='+escape($('query').value)"

the observe field on labt_labtid should be like that, but not the
other one (again, it might be easier to have a single observe form)

Fred

i tried doing it this way… its working fine… also i think i should tell you that in my controller im accessing labtid as params[:labtid] . i tried putting params[:labt][:labtid] but then it completely failed.

can you help me here?? it would be great if you could put some sample code for observe_form . i have no clue how it should work.!

Thanks again alot!

i tried doing it this way.. its working fine.. also i think i should tell you that in my controller im accessing labtid as params[:labtid] . i tried putting params[:labt][:labtid] but then it completely failed.

You need to name the parameter labt[labtid] in your :with option if you want to be able to access it as params[:labt][:labtid] as you do when it's submitted 'normally'

can you help me here?? it would be great if you could put some sample code for observe_form . i have no clue how it should work.!

It's just like observe_field except you give it a form and it will submit the whole form whenever any of it changes.

Fred