Andrew G. Cowan
2006-Apr-10 15:24 UTC
[Rails] form_remote_tag can only have one submit button?
I setup a form_remote_tag with several submit buttons, all of them share the same name ( ''do_action'' ) and their values differ. eg. button1 named do_action with value ACTION1 button2 named do_action with value ACTION2, etc No matter which button I press the value passed is always the one defined for the first of these buttons ( the correct value associated with the pressed button is not passed to the controller ). This behavior does not occur with a regular form_tag, which works as it should passing the value associated with the pressed button. Anyone have any insight into this, surely this is not intended behavior? -Andy
Roberto Saccon
2006-Apr-10 15:32 UTC
[Rails] form_remote_tag can only have one submit button?
It''s the way prototype serializes the form fields. You need to hack something with hidden form fields which get populated via javascript when one of your submit buttons get pressed. On 4/10/06, Andrew G. Cowan <icculus@gmdstudios.com> wrote:> > I setup a form_remote_tag with several submit buttons, all of them share > the same name > ( ''do_action'' ) and their values differ. > > eg. > button1 named do_action with value ACTION1 > button2 named do_action with value ACTION2, > etc > > > No matter which button I press the value passed is always the one > defined for the first of these buttons ( the correct value associated > with the pressed button is not passed to the controller ). > > This behavior does not occur with a regular form_tag, which works as it > should passing the value associated with the pressed button. > > Anyone have any insight into this, surely this is not intended behavior? > > -Andy > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Roberto Saccon - http://rsaccon.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060410/b46151fd/attachment.html
ajax forms don''t work the same as standard html forms, at least as far as submission to the server goes. basically, in the end, the form data gets serialized into a parameter string field1=this&field2=that&field3=foobar if you have 2 form fields (this includes buttons) with the same name, you can see what happens. field1=this&field1=that here is a test (save to your myapp/public directory: <html> <head> <script type="text/javascript" src="/javascripts/prototype.js"></script> </head> <form id="testform" method="post"> <input type="submit" name="do_action" value="1"/> <input type="submit" name="do_action" value="2"/> </form> <script type="text/javascript"> document.write("<code>" + Form.serialize("testform") + "</code>"); </script> load it in the browser and you can see what prototype does to the form in order to prepare the request Chris On 4/10/06, Andrew G. Cowan <icculus@gmdstudios.com> wrote:> > I setup a form_remote_tag with several submit buttons, all of them share > the same name > ( ''do_action'' ) and their values differ. > > eg. > button1 named do_action with value ACTION1 > button2 named do_action with value ACTION2, > etc > > > No matter which button I press the value passed is always the one > defined for the first of these buttons ( the correct value associated > with the pressed button is not passed to the controller ). > > This behavior does not occur with a regular form_tag, which works as it > should passing the value associated with the pressed button. > > Anyone have any insight into this, surely this is not intended behavior? > > -Andy > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060410/29c42884/attachment.html
Andrew Cowan
2006-Apr-10 16:31 UTC
[Rails] Re: form_remote_tag can only have one submit button?
Gothca, thanks for the explanation guys. -Andy Chris Hall wrote:> ajax forms don''t work the same as standard html forms, at least as far > as > submission to the server goes. > > basically, in the end, the form data gets serialized into a parameter > string > > field1=this&field2=that&field3=foobar > > if you have 2 form fields (this includes buttons) with the same name, > you > can see what happens. > > field1=this&field1=that > > > here is a test (save to your myapp/public directory: > > <html> > <head> > <script type="text/javascript" src="/javascripts/prototype.js"></script> > </head> > <form id="testform" method="post"> > <input type="submit" name="do_action" value="1"/> > <input type="submit" name="do_action" value="2"/> > </form> > <script type="text/javascript"> > document.write("<code>" + Form.serialize("testform") + "</code>"); > </script> > > load it in the browser and you can see what prototype does to the form > in > order to prepare the request > > Chris-- Posted via http://www.ruby-forum.com/.