MCPcopy
hub / github.com/react-component/form / validateFieldsInternal

Function validateFieldsInternal

src/createBaseForm.js:463–594  ·  view source on GitHub ↗
(
        fields,
        { fieldNames, action, options = {} },
        callback,
      )

Source from the content-addressed store, hash-verified

461 },
462
463 validateFieldsInternal(
464 fields,
465 { fieldNames, action, options = {} },
466 callback,
467 ) {
468 const allRules = {};
469 const allValues = {};
470 const allFields = {};
471 const alreadyErrors = {};
472 fields.forEach(field => {
473 const name = field.name;
474 if (options.force !== true && field.dirty === false) {
475 if (field.errors) {
476 set(alreadyErrors, name, { errors: field.errors });
477 }
478 return;
479 }
480 const fieldMeta = this.fieldsStore.getFieldMeta(name);
481 const newField = {
482 ...field,
483 };
484 newField.errors = undefined;
485 newField.validating = true;
486 newField.dirty = true;
487 allRules[name] = this.getRules(fieldMeta, action);
488 allValues[name] = newField.value;
489 allFields[name] = newField;
490 });
491 this.setFields(allFields);
492 // in case normalize
493 Object.keys(allValues).forEach(f => {
494 allValues[f] = this.fieldsStore.getFieldValue(f);
495 });
496 if (callback && isEmptyObject(allFields)) {
497 callback(
498 isEmptyObject(alreadyErrors) ? null : alreadyErrors,
499 this.fieldsStore.getFieldsValue(fieldNames),
500 );
501 return;
502 }
503 const validator = new AsyncValidator(allRules);
504 if (validateMessages) {
505 validator.messages(validateMessages);
506 }
507 validator.validate(allValues, options, errors => {
508 const errorsGroup = {
509 ...alreadyErrors,
510 };
511 if (errors && errors.length) {
512 errors.forEach(e => {
513 const errorFieldName = e.field;
514 let fieldName = errorFieldName;
515
516 // Handle using array validation rule.
517 // ref: https://github.com/ant-design/ant-design/issues/14275
518 Object.keys(allRules).some(ruleFieldName => {
519 const rules = allRules[ruleFieldName] || [];
520

Callers

nothing calls this directly

Calls 4

isEmptyObjectFunction · 0.90
getFieldMetaMethod · 0.80
setFieldsMethod · 0.80
getFieldMethod · 0.80

Tested by

no test coverage detected