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

Function validateFields

src/createBaseForm.js:596–654  ·  view source on GitHub ↗
(ns, opt, cb)

Source from the content-addressed store, hash-verified

594 },
595
596 validateFields(ns, opt, cb) {
597 const pending = new Promise((resolve, reject) => {
598 const { names, options } = getParams(ns, opt, cb);
599 let { callback } = getParams(ns, opt, cb);
600 if (!callback || typeof callback === 'function') {
601 const oldCb = callback;
602 callback = (errors, values) => {
603 if (oldCb) {
604 oldCb(errors, values);
605 }
606 if (errors) {
607 reject({ errors, values });
608 } else {
609 resolve(values);
610 }
611 };
612 }
613 const fieldNames = names
614 ? this.fieldsStore.getValidFieldsFullName(names)
615 : this.fieldsStore.getValidFieldsName();
616 const fields = fieldNames
617 .filter(name => {
618 const fieldMeta = this.fieldsStore.getFieldMeta(name);
619 return hasRules(fieldMeta.validate);
620 })
621 .map(name => {
622 const field = this.fieldsStore.getField(name);
623 field.value = this.fieldsStore.getFieldValue(name);
624 return field;
625 });
626 if (!fields.length) {
627 callback(null, this.fieldsStore.getFieldsValue(fieldNames));
628 return;
629 }
630 if (!('firstFields' in options)) {
631 options.firstFields = fieldNames.filter(name => {
632 const fieldMeta = this.fieldsStore.getFieldMeta(name);
633 return !!fieldMeta.validateFirst;
634 });
635 }
636 this.validateFieldsInternal(
637 fields,
638 {
639 fieldNames,
640 options,
641 },
642 callback,
643 );
644 });
645 pending.catch(e => {
646 // eslint-disable-next-line no-console
647 if (console.error && process.env.NODE_ENV !== 'production') {
648 // eslint-disable-next-line no-console
649 console.error(e);
650 }
651 return e;
652 });
653 return pending;

Callers 2

start-end-date.jsFile · 0.85

Calls 6

getParamsFunction · 0.90
hasRulesFunction · 0.90
getValidFieldsNameMethod · 0.80
getFieldMetaMethod · 0.80
getFieldMethod · 0.80

Tested by

no test coverage detected