0

I'm using the jQuery validation plugin. When I click the 'My btn' button the form needs to submit without validation. Even if the title is empty it should be able submit by only clicking the 'My btn' button. Is there any way to do this?

<form class="callBkfrm" method="POST" action="/my_action">
  <input type="text" name="title" />
  <button class='btn' type="button">My btn</button>
  <button type="submit">Submit</button>
</form>
$(".myFrm").validate({
  rules: {
    title: {
      required: true
    },
  }
});
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
vimuth
  • 5,064
  • 33
  • 79
  • 116
  • At the bottom of the SO about [jquery-validate](https://stackoverflow.com/tags/jquery-validate/info). Edit: seems to be outdated, see https://jqueryvalidation.org/reference/#link-skipping-validation-on-submit – freedomn-m May 19 '20 at 09:39

1 Answers1

2

From the jquery-validate reference*:


Skipping validation on submit

To skip validation while still using a submit-button, add the attribute formnovalidate to that input:

<input type="submit" name="go" value="Submit">
<input type="submit" formnovalidate name="cancel" value="Cancel">

This used to work by adding class="cancel" to the input, this is now deprecated.

Demo for the cancel button

*copied here for reference

freedomn-m
  • 27,664
  • 8
  • 35
  • 57