Two button form: validate only if one of the button clicked ? #1335
-
I have a two button form (A and B) and some validation rules. The validation rules are now checked when any button is clicked. Is it possible to ignore the validation rules when button A is clicked and checked only when button B is clicked ? If yes, how could I do that ? The use case is a login form with a sign up and a sign in button. The validation rules should only be checked when the sign in button is clicked. |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments
-
Setting the I managed to create a button that skip validation by setting it’s type to "button" and adding a javascript click event handler that loads another page. Unfortunately, it’s not the same as a form submit button that would transmit the content of the form fields. |
Beta Was this translation helpful? Give feedback.
-
That would be the correct way to achieve this. The type of a button element is |
Beta Was this translation helpful? Give feedback.
-
@chmike The second submit button could remove the field rules and then submit the form as usual $('.ui.secondary.submit.button').click(function(){
myform.form('remove fields',['login','password']);
}); |
Beta Was this translation helpful? Give feedback.
-
@ColinFrick I didn’t know one could style an A element as a button. This allows me to drop the javascript @lubber-de what is the effect of removing the fields ? Are they simply removed from the validation process and the field values are still sent to the form action page ? Otherwise, it would have the same net effect as the A element which is simpler for me to understand and implement. |
Beta Was this translation helpful? Give feedback.
-
@chmike It removes all rules of the given fields. So if you remove all fields rules, the submit goes through :) |
Beta Was this translation helpful? Give feedback.
-
So, yes: the field values are still there and will be submitted |
Beta Was this translation helpful? Give feedback.
-
@lubber-de Excellent. It worked with my form. That’s a better solution because I wanted to get the content of the fields. Thank you very much. |
Beta Was this translation helpful? Give feedback.
@chmike The second submit button could remove the field rules and then submit the form as usual
See https://jsfiddle.net/xkhepq9c/