comindware.core.ui
Version:
Comindware Core UI provides the basic components like editors, lists, dropdowns, popups that we so desperately need while creating Marionette-based single-page applications.
35 lines (31 loc) • 1 kB
text/typescript
import LocalizationService from '../../services/LocalizationService';
import _ from 'underscore';
export default function(options) {
options = _.extend(
{
type: 'length',
message: LocalizationService.get('CORE.FORM.VALIDATION.LENGTH')
},
options
);
return function length(value) {
const val = _.isObject(value) ? value.value : value;
options.value = val;
const err = {
type: options.type,
message: typeof options.message === 'function' ? options.message(options) : options.message
};
//Don't check empty values (add a 'required' validator for this)
if (val === null || val === undefined || val === '') return;
if (options.min) {
if (val.length < options.min) {
return err;
}
}
if (options.max) {
if (val.length > options.max) {
return err;
}
}
};
}