garygreen / dominar

Lightweight bootstrap validator inspired by Laravel
http://garygreen.github.io/dominar/
22 stars 4 forks source link

Make 'rules' optional #9

Closed garygreen closed 9 years ago

garygreen commented 9 years ago

Useful if you want to build a list of rules manually with validatorOptions.

Example, field 'b' is required when a is present. The proposed required_with rule in validatorjs would help as well.

var validator = new Dominar($('form'), {
    a: {
        rules: 'required'
    },
    b: {
        validatorOptions: function(options) {
            if (this.getField('a').getValue().length) {
                options.rules = 'required';
            }
            return options;
        }
    }
});
garygreen commented 9 years ago

Works fine in fb1df106239488e74b63dd7eacb779371166370c