@alifd/next
Version:
A configurable component library for web built on React.
28 lines (22 loc) • 1.01 kB
JavaScript
;
exports.__esModule = true;
var _util = require('../util');
var util = _interopRequireWildcard(_util);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
/**
* Rule for validating required fields.
*
* @param rule The validation rule.
* @param value The value of the field on the source object.
* @param errors An array of errors that this rule may add
* validation errors to.
* @param options The validation options.
* @param options.messages The validation messages.
*/
function required(rule, value, errors, options) {
if (value === undefined || value === null || value === '' || value.length === 0) {
errors.push(util.format(options.messages.required, rule.field));
}
}
exports.default = required;
module.exports = exports['default'];