Good day. I am going to attempt this problem I am having from another angle seeing as either I am doing something so stupid that no one wants to comment on it, or because I am just so lost that no one has seen or done things this way before. I am simply wanting to update multiple fields of a form after one onchange event occurs. I am currently using multiple observe_field calls on the same input_id, however, I get a too much recursion error in the javascript when this is executed. I would like to use the update_element_function, but it appears to me to only work on submission of the form, as the action in the element created says onsubmit(). I need the form to update once the user makes a selection from a drop down list and then populate values in 3+ other fields. Has anyone done this before? Is this not common practice in javascript and with forms? Thanks, _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Hi Damon, Do you have some code to show? That would make things a bit easier to comment on... Best regards, torben
Torben--
Thanks for the reply.
I do have some code that I posted yesterday in another thread, but would
love to post here again for you :)
Main View
<td><label for="purchase_order_cutomer_address">Customer
Address:</label></td>
<td><div id="po_customer_address"></div></td>
</tr>
<tr>
<td><label for="purchase_order_shipper_address">Ship
Via:</label></td>
<td><div id="po_shipper_address"></div></td>
<td> </td>
<td><label for="purchase_order_credit_limit">Credit
Limit:</label></td>
<td><div id="po_credit_limit"></div></td>
<td><label for="purchase_order_current_balance">Current
Bal:</label></td>
<td><div id="po_current_balance"></div></td>
</tr>
</table>
<%= observe_field(:purchase_order_customer_id,
:update => :po_customer_address,
:url => { :action => :get_customer_address },
:with => "''customer_id=''+escape(value)")%>
<%= observe_field(:purchase_order_customer_id,
:update => :po_credit_limit,
:url => { :action => :get_customer_credit_limit },
:with => "''customer_id=''+escape(value)")%>
Controller
def get_customer_address
form_customer_id = params[:customer_id]
@found_customer = Customer.find(form_customer_id)
end
def get_customer_credit_limit
form_customer_id = params[:customer_id]
@found_customer_limit = Customer.find(form_customer_id)
end
Returning Views
get_customer_address.rhtml
<%= text_field("purchase_order", "customer_address",
:readonly =>
"readonly", "size" => 25, :value =>
@found_customer.address) %><br />
<%= text_field("purchase_order", "customer_city",
:readonly => "readonly",
"size" => 10, :value => @found_customer.city) %>
<%= text_field("purchase_order", "customer_state",
:readonly => "readonly",
"size" => 2, :value => @found_customer.state) %>
<%= text_field("purchase_order", "customer_postal_code",
:readonly =>
"readonly", "size" => 5, :value =>
@found_customer.postal_code) %>
get_customer_credit_limit.rhtml
<%= text_field("purchase_order", "customer_credit_limit",
:readonly =>
"readonly", :value => @found_customer_limit.credit_limit) %>
Thanks!
~damon
On 11/17/05, Torben Wölm
<torben.wolm-XColJK2Sf8R0cC2WI2GV6A@public.gmane.org>
wrote:>
> Hi Damon,
>
> Do you have some code to show? That would make things a bit easier to
> comment on...
>
> Best regards,
> torben
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails
Hi Damon
I can''t say that I have tried the thing you want, but I had a look in
the "Agile Development"-book that holds a tip I think might be usable.
The tip goes, that you return a bunch of generated javascript that you evaluate
in the client.
So, you will do something like:
observe_field(:purchase_order_customer_id,
  :complete => "eval(request.responseText)",
  :url => { :action => :get_all_customer_info },
  :with => "''customer_id=''+escape(value)")
In the template, you generate the javascript that updates all the fields:
document.getElementById("po_customer_address").value =
''<%= @found_customer.address %>'';
document.getElementById("po_credit_limit").value = ''<%=
@found_customer_limit.credit_limit %>'';
and so on.
Hope this helps...
Torben
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails
imobachgs-gShqw608wn4@public.gmane.org
2005-Nov-17  19:36 UTC
RE: Update multiple fields in a form on change event
El Jueves 17 Noviembre 2005 19:20, Torben Wlm escribi:> Hi Damon > > I can''t say that I have tried the thing you want, but I had a look in the > "Agile Development"-book that holds a tip I think might be usable. > > The tip goes, that you return a bunch of generated javascript that you > evaluate in the client. > > So, you will do something like: > > observe_field(:purchase_order_customer_id, > > :complete => "eval(request.responseText)", > :url => { :action => :get_all_customer_info }, > :with => "''customer_id=''+escape(value)") > > In the template, you generate the javascript that updates all the fields: > > document.getElementById("po_customer_address").value = ''<%> @found_customer.address %>''; > document.getElementById("po_credit_limit").value = ''<%> @found_customer_limit.credit_limit %>'';I think that you have an "update_element_function"[1] to do such a thing. Good luck! [1] http://api.rubyonrails.org/classes/ActionView/Helpers/JavaScriptHelper.html#M000430 -- _o) Imobach Gonzlez Sosa //\ email: imobachgs at step dot es V_/_ jid: osoh at jabberes dot org url: http://www.banot.net/~osoh/ blog: http://devnull.blogs.banot.net/ ------------------- http://www.step.es/ -- Este mensaje ha sido analizado por STEP On Line en busca de virus y otros contenidos peligrosos, y se considera que est limpio. 902 10 18 43
>I think that you have an "update_element_function"[1] to do such a thing. > >Good luck!>[1] >http://api.rubyonrails.org/classes/ActionView/Helpers/JavaScriptHelper.html#M000430Ahh - sweet. The documentation even holds an example of -- how to make multiple updates! Thanks, Torben _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Thanks for the replies Torben and Imobach. I did attempt to implement the update_element_function however, the action it was looking for was an onSubmit() and I need the form to update on an onEvent() action. I will look again and see if there is a way to set which action the update_element_function looks for. Thanks again, ~damon On 11/17/05, Torben Wölm <torben.wolm-XColJK2Sf8R0cC2WI2GV6A@public.gmane.org> wrote:> > >I think that you have an "update_element_function"[1] to do such a thing. > > > >Good luck! > > >[1] > > > http://api.rubyonrails.org/classes/ActionView/Helpers/JavaScriptHelper.html#M000430 > > Ahh - sweet. The documentation even holds an example of -- how to make > multiple updates! > > Thanks, > Torben > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Solved!!!
The examples and hints given by Torben worked beautifully! Thanks!
Here is my view now:
<tr>
<td colspan="2" align="right"><label
for="purchase_order_cutomer_address">Customer
Address:</label></td>
<td colspan="2"><input type="text"
id="po_customer_address" ></td>
<td><label for="purchase_order_shipper_address">Shipper
Address:</label></td>
<td><div id="po_shipper_address"></div></td>
</tr>
<tr>
<td colspan="2"> </td>
<td colspan="2"><input type="text"
id="po_customer_city"> <input type="text"
id="po_customer_state"> <input type="text"
id="po_customer_postal_code"></td>
</tr>
<tr>
<td><label for="purchase_order_credit_limit">Credit
Limit:</label></td>
<td><input type="text"
id="po_credit_limit"></td>
<td><label for="purchase_order_current_balance">Current
Bal:</label></td>
<td><input type="text"
id="po_current_balance"></td>
<td><label for="purchase_order_customer_pickup">Customer
Pickup:</label</td>
<td><%= check_box_tag("po_customer_pickup",
value="1", checked=false)
%></td>
</tr>
<%= observe_field(:purchase_order_customer_id,
:complete => "eval(request.responseText)",
:url => { :action => :get_customer_info },
:with => "''customer_id=''+escape(value)")%>
My controller just finds the specified customer record designated by
customer_id.
Then the get_customer_info.rhtml looks like this:
document.getElementById("po_customer_address").value =
''<%@found_customer.address %>'';
document.getElementById("po_customer_city").value =
''<%@found_customer.city %>'';
document.getElementById("po_customer_state").value =
''<%@found_customer.state %>'';
document.getElementById("po_customer_postal_code").value =
''<%@found_customer.postal_code %>'';
document.getElementById("po_credit_limit").value =
''<%@found_customer.credit_limit %>'';
document.getElementById("po_current_balance").value =
''<%@found_customer.inv_balance %>'';
Thanks again!
On 11/17/05, Damon Hill
<mdamonhill-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
> Thanks for the replies Torben and Imobach.
> I did attempt to implement the update_element_function however, the action
> it was looking for was an onSubmit() and I need the form to update on an
> onEvent() action.
>
> I will look again and see if there is a way to set which action the
> update_element_function looks for.
>
> Thanks again,
> ~damon
>
> On 11/17/05, Torben Wölm
<torben.wolm-XColJK2Sf8R0cC2WI2GV6A@public.gmane.org> wrote:
> >
> > >I think that you have an "update_element_function"[1] to
do such a
> > thing.
> > >
> > >Good luck!
> >
> > >[1]
> >
>http://api.rubyonrails.org/classes/ActionView/Helpers/JavaScriptHelper.html#M000430
> >
> > Ahh - sweet. The documentation even holds an example of -- how to make
> > multiple updates!
> >
> > Thanks,
> > Torben
> >
> > _______________________________________________
> > Rails mailing list
> > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> > http://lists.rubyonrails.org/mailman/listinfo/rails
> >
> >
> >
>
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails