Saravanan Saravanan - 1 year ago 150
jQuery Question

Dynamic Validation using jqBootstrapValidation

Suppose I have a button (type is not Submit) and an event attached to a button like below

$("#idProceedBtn").on("click", function (e) {.....}

I will need to perform the action in the event only after validation passes. I can achieve this by else condition of the below statement


Doing this is working, but it is not highlighting which fields are failing validation and why, like what happens when a button with type submit clicked.

Answer Source

I've found a solution by modifying of "hasErrors" method in jqBootstrapValidation.js - I've added the trigger to "submit.validation":

hasErrors: function() {

    var errorMessages = [];

    this.each(function (i, el) {
      errorMessages = errorMessages.concat(
        $(el).triggerHandler("getValidators.validation") ? $(el).triggerHandler("validation.validation", {submitting: true}) : []

    return (errorMessages.length > 0);

Now it is highlighting errors in form as expected.