required.js 698 B

1234567891011121314151617181920
  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 && (!source.hasOwnProperty(rule.field) || util.isEmptyValue(value, type || rule.type))) {
  15. errors.push(util.format(options.messages.required, rule.fullField));
  16. }
  17. }
  18. export default required;