lowcoupling
lowcoupling

Reputation: 2169

Form Validation in Bootstrap Modal

I am trying to use this nice plugin http://reactiveraven.github.io/jqBootstrapValidation/ in a Form contained in a Bootstrap Modal. The only problem I am facing is about required fields which are supposed to be checked when the modal button is pressed. The problem is that as the button is outside the form (and the form control group) it is not managed by the validation plugin. How should I deal with it?

This is what I am trying to achieve but I can't actually understand the proposed solution https://github.com/ReactiveRaven/jqBootstrapValidation/issues/22

Upvotes: 0

Views: 1179

Answers (1)

asdf_enel_hak
asdf_enel_hak

Reputation: 7650

You can create a submit button inside of form and hide it.
When button pressed outside of form, you trigger button click() inside of form

$("#myButton2").on("click", function() {     
   $("#myButton1").click();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="myForm" action="#">
  <input type="checkbox" name="myCheckbox" id="myCheckbox" required />  my checkbox
  <input type="submit" style="display:none" id="myButton1" />
</form>
<input type="button" id="myButton2" value="button">

Upvotes: 2

Related Questions