Reputation: 1473
I have a form with multiple fields, including a coupon code. I want the user to be able to independently check if the coupon code is valid without submitting the entire form. I created a form and "Check" submit_tag for the coupon code on its own, which works fine. However, if I put it inside the main form, when the user clicks on "Check" the entire form is submitted. If I put it outside the main form, the coupon code won't be included when the main form is submitted.
How can I include the small form inside the main form, and still allow it to be checked independently?
Possible Solution:
I can put the "Check" form outside the main form and add a duplicate coupon field to the main form and fill it in with javascript on submission, but I was wondering if there's a better way.
Upvotes: 1
Views: 891
Reputation: 1722
Why not just use javascript and a link that looks like a button to check asynchronously?
The button shouldn't trigger the form submit action, and you can update the view according to the js response.
The other advantage of doing it this way is that you won't lose all the form data on refresh.
Upvotes: 1