简体   繁体   中英

jQuery validation engine always failing validation with select2

I am running into a strange issue where, instead of it not validating at all using the pos absolute jquery validation engine plugin, the field is over-validating aka, we are always getting the "Field is required" prompt.

Here is my html:

<div class="control-group">
    <label for="funeral_director" class="control-label">Funeral Director</label>

    <div class="controls">
        <select name="funeral_director" id="funeral_director" class="validate[required]">
            <option value=""></option>
            <option value="13">Test User</option>
            <option value="4">Admin User</option>
            <option value="1">Dev User</option>
        </select>
    </div>
</div>

Here is my select2 javascript:

$('#funeral_director').select2({
    blurOnChange: true,
    placeholder: 'Director',
    width: 'resolve'
});

And here is my validation engine javascript:

$("#addForm").validationEngine({
                prettySelect: true,
                usePrefix: 's2id_'
            });

I don't think it matters as I also tried moving the select2 instantiation into the same file both before and after the validation instantiation., but both lots of javascript are getting called in $(function(){/*..code*/}) blocks, but in separate files, the validation engine initialization file is included before the select2 initialization file.

Select2: 3.3.1
jqve: 2.6.2

In select2.min.js find this strokes (should be 2 strokes in script):

D(this.container,this.opts.element,this.opts.adaptContainerCssClass)

and add this code right after stroke you've found

,this.container.removeClass("validate[required]")

this should solve your problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM