Search code examples
jquerytwitter-bootstrap-3jquery-validation-engine

How to make jquery validation engine work at bootstrap


I'm trying to use this plugin at my bootstrap page. It'll be very simple. Just show a message if the field is empty. But, I can't make it work! I don't understand why, it's not working. Here is the fiddle.


Solution

  • First you need to load the correct locale, then you have to include a way to validate the form on the submit button.

    Check this fiddle: http://jsfiddle.net/v5v2x7u7/

    <form role="form" id="formID">
        <div class="form-group validation-content">
            <label>Name</label>
            <input value="" class="form-control validate[required]" type="text" name="name" id="name" />
        </div>
        <div class="form-group validation-content">
            <label>Email</label>
            <input value="" class="form-control validate[required,custom[email]]" type="text" name="email" id="email" />
        </div>
        <div class="form-group validation-content">
            <label>Message</label>
            <textarea value="" class="form-control validate[required]" name="message" id="message"></textarea>
        </div>
        <button type="button" class="btn btn-primary" onclick="validate();">Submit</button>
    </form>
    
    validate = function(){
        $("#formID").validationEngine('validate');
    }