bootstrap-validator icon indicating copy to clipboard operation
bootstrap-validator copied to clipboard

Can form validation work with bootstrap select ?

Open jxzhangxing opened this issue 6 years ago • 2 comments

jxzhangxing avatar Aug 30 '18 03:08 jxzhangxing

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/

MysteriousNothing avatar Aug 30 '18 07:08 MysteriousNothing

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.

jxzhangxing avatar Oct 30 '18 07:10 jxzhangxing