required.js 703 B

123456789101112131415161718192021
  1. import * as util from '../util';
  2. /**
  3. * Rule for validating required fields.
  4. *
  5. * @param rule The validation rule.
  6. * @param value The value of the field on the source object.
  7. * @param source The source object being validated.
  8. * @param errors An array of errors that this rule may add
  9. * validation errors to.
  10. * @param options The validation options.
  11. * @param options.messages The validation messages.
  12. */
  13. function required(rule, value, source, errors, options, type) {
  14. if (rule.required &&
  15. (!source.hasOwnProperty(rule.field) || util.isEmptyValue(value, type || rule.type))) {
  16. errors.push(util.format(options.messages.required, rule.fullField));
  17. }
  18. }
  19. export default required;