Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
155
rated 0 times [  161] [ 6]  / answers: 1 / hits: 71191  / 8 Years ago, thu, february 18, 2016, 12:00:00

UPDATE:
my question is more about How to prevent the form submit if the validation fails



the link does not solve my problem



just re-iterate what I'm doing:
I have a form with bunch of input fields and when the user hit the submit button it validate form using attribute required=required if the form validation fails THEN I want to stop submitting the form as you see the javascript it show the div when the user submit the form.



Hope this clears up.



END UPDATE



How can I stop the form submit to fire if the form validation fails?



<input class=form-control data-val=true id=SerialNumber name=SerialNumber required=required type=text>

<button type=submit name=rsubmit class=btn btn-success>Submit</button>

//loading message:
$(form).submit(function (e) {
$(#loading).show();
});

More From » jquery

 Answers
23

I able to fixed the problem:



First add the ref on your page:



<script src=http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js></script>
<script src=http://ajax.aspnetcdn.com/ajax/mvc/3.0/jquery.validate.unobtrusive.min.js></script>


then do this check:



        $(form).submit(function () {
if ($(this).valid()) { //<<< I was missing this check
$(#loading).show();
}
});

[#63270] Tuesday, February 16, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rossthomasn

Total Points: 122
Total Questions: 78
Total Answers: 105

Location: South Georgia
Member since Sun, Aug 8, 2021
3 Years ago
rossthomasn questions
Wed, Mar 16, 22, 00:00, 2 Years ago
Wed, May 5, 21, 00:00, 3 Years ago
Thu, Nov 26, 20, 00:00, 4 Years ago
Sun, May 31, 20, 00:00, 4 Years ago
;