jquery - How to prevent Boostrapvalidator from disabling all buttons on a form? -


i'm using boostrapvalidator nghuuphuoc , i've situation, when validation fired buttons disabled. problem me because want specific button skipped validation. there anyway of doing using validator?

thanks!

i came across same problem wants keep 2 buttons alive if form has invalid field(s).

figured out three possible solutions.

by default, submit button(s) disabled if there @ least 1 invalid field

minimal generic example having multiple buttons disabled if form field(s) invalid.

solution-1

change other button's type type="submit" type="button" keep other buttons alive , disable submit button if form field(s) invalid.

fiddle


solution-2

add attribute name="submitme" only form submit button , define in bootstrapvalidator plugin call.
important: not use attribute name="submit" if submit button remain disabled if field(s) valid.

note: in solution, buttons have type="submit"

$(document).ready(function () {     $('#selector').bootstrapvalidator({         submitbuttons: 'button[name="submitme"]',         // rest of validation code goes here     }); }); 

this disable submit button , keep other buttons alive if form field(s) invalid.

fiddle


solution-3

use form event status.field.bv , check if form field(s) valid or not keep other button's alive

note: solution tested , work new version 0.5.3

$(document).ready(function () {     $('#selector').bootstrapvalidator({         // rest of validation code goes here     }).on('status.field.bv', function (e, data) {         formisvalid = true;          if(formisvalid) {              $('#cancel').attr('disabled', false);             $('#reset').attr('disabled', false);         }     }); }); 

note: added id's button(s) needs alive if form field(s) invalid.

fiddle


Comments