backbone.validation icon indicating copy to clipboard operation
backbone.validation copied to clipboard

Attribute "greater than"

Open fatimaTalavera opened this issue 7 years ago • 1 comments

Is an extension of the min attribute possible, which only allows greater?

fatimaTalavera avatar Oct 20 '17 15:10 fatimaTalavera

Yes, you can use something like this.

_.extend(Backbone.Validation.validators, {
          greaterThan : function (value, attr, minValue, model) {
                var val = parseInt(value, 10);
                if (_.isNaN(val) || val <= minValue) {
                    return this.format("{0} must be greater than {1}",
                        this.formatLabel(attr, model), minValue);
                }
            }
}

Amsvartner avatar Apr 25 '18 11:04 Amsvartner