1000hz / bootstrap-validator

A user-friendly HTML5 form validation jQuery plugin for Bootstrap 3
http://1000hz.github.io/bootstrap-validator
MIT License
2.38k stars 1.07k forks source link

Can form validation work with bootstrap select ? #633

Open jxzhangxing opened 6 years ago

MysteriousNothing commented 6 years ago

You can make custom validation if you want validate something in select list. if you want just validate select it self then add required to it.

Anyway custom validation is done so like that: add data-equals="foo" input/select

$('form').validator({
        custom: {
            equals: function($el) {
                var matchValue = $el.data("equals") // foo
                if ($el.val() !== matchValue) {
                    return "Hey, that's not valid! It's gotta be " + matchValue
                }
            }
        }
    });

See doc for more info: http://1000hz.github.io/bootstrap-validator/

jxzhangxing commented 5 years ago

Finally I realize the meaning. I added a custom validator to the bootstrap select element which looks like: let select = $('<SELECT />', { 'data-live-search': true, 'id': item['property-name'], 'class': 'form-control selectpicker show-tick', 'data-validate': true, 'data-omnicolumn': 'exampre', 'data-omnicolumn-error': 'example-error' }); and it works fine.