Forum: Ruby on Rails howto set the form_id in the button_to method

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
mdamonhill (Guest)
on 2005-12-06 19:42
(Received via mailing list)
I have a very simple procedure that I am trying to implement.
I have the following code in my controller:

    <%= text_field(:invoice, :id, :size => 20, :onkeydown =>
%Q($('button-id').action = '#{url_for(:controller => 'invoice', :action
=>
'edit')}?id=' + $F('invoice_id');)) %>
    <%= button_to ('Goto Invoice #', {:id => 'invoice_id', :action =>
:edit}, {:id => 'button-id'}) %>

(Thanks to the help of Francois, btw).

I want to simply have the user enter and invoice # and press the button
that
will then show the selected invoice in with the edit action.
However, I need to be able to set the form id that is automatically
generated by the button_to method to use the above javascript.

Does anyone know how to do this?
Or is there an easier way to accomplish my goal here?

Thanks,
~damon
francois.beausoleil (Guest)
on 2005-12-07 02:14
(Received via mailing list)
Hello Damon,

2005/12/6, Damon H. <removed_email_address@domain.invalid>:
> I want to simply have the user enter and invoice # and press the button that
> will then show the selected invoice in with the edit action.
> However, I need to be able to set the form id that is automatically
> generated by the button_to method to use the above javascript.

Looking at the button_to macro, there is no way currently to set the
form's ID.

> Does anyone know how to do this?
> Or is there an easier way to accomplish my goal here?

Just thought of something - you're not by any chance nesting forms
too, right ?  That's disallowed.

If you are not nesting forms, then the following should work:
<%= start_form_tag :controller => 'invoice', :action => 'edit' %>
  <label>Invoice No: <%= text_field 'invoice', 'id' %></label>
  <%= submit_tag 'Go' %>
<%= end_form_tag %>

That should do the trick.

DTSTTCPW (Do The Simplest Thing That Could Possibly Work)...

Bye !
This topic is locked and can not be replied to.