| 1007 | }; |
| 1008 | |
| 1009 | const trigger: UseFormTrigger<TFieldValues> = async (name, options = {}) => { |
| 1010 | let isValid; |
| 1011 | let validationResult; |
| 1012 | const fieldNames = convertToArrayPayload(name) as InternalFieldName[]; |
| 1013 | |
| 1014 | if (_options.resolver) { |
| 1015 | const errors = await executeSchemaAndUpdateState( |
| 1016 | isUndefined(name) ? name : fieldNames, |
| 1017 | ); |
| 1018 | |
| 1019 | isValid = isEmptyObject(errors); |
| 1020 | validationResult = name |
| 1021 | ? !fieldNames.some((name) => get(errors, name)) |
| 1022 | : isValid; |
| 1023 | } else if (name) { |
| 1024 | validationResult = ( |
| 1025 | await Promise.all( |
| 1026 | fieldNames.map(async (fieldName) => { |
| 1027 | const field = get(_fields, fieldName); |
| 1028 | return await executeBuiltInValidation({ |
| 1029 | fields: field && field._f ? { [fieldName]: field } : field, |
| 1030 | eventType: EVENTS.TRIGGER, |
| 1031 | }); |
| 1032 | }), |
| 1033 | ) |
| 1034 | ).every(Boolean); |
| 1035 | !(!validationResult && !_formState.isValid) && _setValid(); |
| 1036 | } else { |
| 1037 | validationResult = isValid = await executeBuiltInValidation({ |
| 1038 | fields: _fields, |
| 1039 | name, |
| 1040 | eventType: EVENTS.TRIGGER, |
| 1041 | }); |
| 1042 | } |
| 1043 | |
| 1044 | _subjects.state.next({ |
| 1045 | ...(!isString(name) || |
| 1046 | ((_proxyFormState.isValid || _proxySubscribeFormState.isValid) && |
| 1047 | isValid !== _formState.isValid) |
| 1048 | ? {} |
| 1049 | : { name }), |
| 1050 | ...(_options.resolver || !name ? { isValid } : {}), |
| 1051 | errors: _formState.errors, |
| 1052 | }); |
| 1053 | |
| 1054 | options.shouldFocus && |
| 1055 | !validationResult && |
| 1056 | iterateFieldsByAction( |
| 1057 | _fields, |
| 1058 | _focusInput, |
| 1059 | name ? fieldNames : _names.mount, |
| 1060 | ); |
| 1061 | |
| 1062 | return validationResult; |
| 1063 | }; |
| 1064 | |
| 1065 | const getValues: UseFormGetValues<TFieldValues> = ( |
| 1066 | fieldNames?: |