Initial commit
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
module.exports = function (options) {
|
||||
var type = options.columnType;
|
||||
var collection = options.columnsCollection;
|
||||
|
||||
var error = {
|
||||
type: options.type,
|
||||
message: _t('components.backbone-forms.column-type-error', { columnType: type })
|
||||
};
|
||||
|
||||
return function columnType (value) {
|
||||
var column = collection.findWhere({ name: value });
|
||||
var matchesType = column && column.get('type') === type;
|
||||
|
||||
if (!matchesType) return error;
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
module.exports = function (opts) {
|
||||
// get the min value
|
||||
var minValue = parseFloat(opts.min) || 0;
|
||||
var maxValue = parseFloat(opts.max) || 0;
|
||||
var err = {
|
||||
type: opts.type,
|
||||
message: _t('components.backbone-forms.interval-error', { minValue: opts.min, maxValue: opts.max })
|
||||
};
|
||||
return function interval (value, attrs) {
|
||||
var fieldValue = 0;
|
||||
|
||||
if (value === null || value === undefined || value === '') return err;
|
||||
|
||||
// check if the value is number
|
||||
if (!isNaN(parseFloat(value)) && isFinite(value)) {
|
||||
fieldValue = parseFloat(value);
|
||||
}
|
||||
if (minValue > fieldValue || maxValue < fieldValue) {
|
||||
return err;
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Adds a new validator for Boolean fields, based on Form.validators.required
|
||||
*/
|
||||
|
||||
module.exports = function (options) {
|
||||
var err = {
|
||||
type: 'required',
|
||||
message: _t('components.backbone-forms.required-boolean-error')
|
||||
};
|
||||
|
||||
return function required (value) {
|
||||
if (value === undefined) return err;
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user