required.js 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _util = require('../util');
  6. var util = _interopRequireWildcard(_util);
  7. 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; } }
  8. /**
  9. * Rule for validating required fields.
  10. *
  11. * @param rule The validation rule.
  12. * @param value The value of the field on the source object.
  13. * @param source The source object being validated.
  14. * @param errors An array of errors that this rule may add
  15. * validation errors to.
  16. * @param options The validation options.
  17. * @param options.messages The validation messages.
  18. */
  19. function required(rule, value, source, errors, options, type) {
  20. if (rule.required && (!source.hasOwnProperty(rule.field) || util.isEmptyValue(value, type || rule.type))) {
  21. errors.push(util.format(options.messages.required, rule.fullField));
  22. }
  23. }
  24. exports['default'] = required;
  25. module.exports = exports['default'];