4

The issue:

I have Bootstrap modal buttons in a form that open a modal to select data (users and cost types), these buttons are not meant to submit the main form.

When I press the modal buttons the modal opens only when other required fields are empty. When the required fields are filled in by a user the form submits (this is not hat I expect).

How can I prevent the form from submitting when trying to open a modal?

e.preventDefault(); does not prevent the form from submitting.

A jsfiddle can be found here: http://jsfiddle.net/cagy79/193thboq/

Any ideas?

2
  • 1
    Your JSFiddle is full of errors. Look at the console.
    – user4639281
    Aug 20, 2015 at 23:18
  • Yes I know, first time i used it, took me 30 minutes just to get this fiddle working a little bit :)
    – Cagy79
    Aug 21, 2015 at 20:41

1 Answer 1

16

Just add an input type of "button" to your HTML. Then you don't need your dontSubmit class.

<button data-toggle="modal" data-target="#modalAddStaff" type="button" >

The reason this is: In HTML5,any button without a type defaults to a "submit" type.

Hope that helps!

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.