jquery - MVC client side validation messages are displayed despite .cancel class -
i have submit button on mvc form (with unobtrusive validation enabled) has cancel class:
<input type="submit" name="go back" value="1" class="cancel" />
the cancel
class allows form post if input fields have validation errors. validation error messages nonetheless displayed button clicked, , remain visible until server completes round trip , page redisplayed.
is there baked mvc i'm missing, or need write own js code find , hide validation messages if submit element has "cancel" class?
disable client-side validation in mvc 3 "cancel" submit button
people seems have popup validation problem , saying in comment that's it's not working in mvc4 , mvc5.
personnaly, il suggest control behavior on form submit event , use ajax post form.
$("myform").submit(function( event ) { event.preventdefault(); //prevent default submit if (!$(this).find("input[type=submit]").hasclass("cancel")) { if (!$("form").validate()) { return false; } } $.ajax({ type: "post", url: url, data: $("myform").serialize(), // serializes form's elements. success: function(data) { //do } }); });
i'm not sure prevent validation poping on submit button click.
an other solution change submit button normal button , control validation , submit of form on own.
Comments
Post a Comment