MCPcopy
hub / github.com/react-hook-form/react-hook-form / trigger

Function trigger

src/logic/createFormControl.ts:1157–1211  ·  view source on GitHub ↗
(name, options = {})

Source from the content-addressed store, hash-verified

1155 };
1156
1157 const trigger: UseFormTrigger<TFieldValues> = async (name, options = {}) => {
1158 let isValid;
1159 let validationResult;
1160 const fieldNames = convertToArrayPayload(name) as InternalFieldName[];
1161
1162 if (_options.resolver) {
1163 const errors = await executeSchemaAndUpdateState(
1164 isUndefined(name) ? name : fieldNames,
1165 );
1166
1167 isValid = isEmptyObject(errors);
1168 validationResult = name
1169 ? !fieldNames.some((name) => get(errors, name))
1170 : isValid;
1171 } else if (name) {
1172 validationResult = (
1173 await Promise.all(
1174 fieldNames.map(async (fieldName) => {
1175 const field = get(_fields, fieldName);
1176 return await executeBuiltInValidation({
1177 fields: field && field._f ? { [fieldName]: field } : field,
1178 eventType: EVENTS.TRIGGER,
1179 });
1180 }),
1181 )
1182 ).every(Boolean);
1183 !(!validationResult && !_formState.isValid) && _setValid();
1184 } else {
1185 validationResult = isValid = await executeBuiltInValidation({
1186 fields: _fields,
1187 name,
1188 eventType: EVENTS.TRIGGER,
1189 });
1190 }
1191
1192 _subjects.state.next({
1193 ...(!isString(name) ||
1194 ((_proxyFormState.isValid || _proxySubscribeFormState.isValid) &&
1195 isValid !== _formState.isValid)
1196 ? {}
1197 : { name }),
1198 ...(_options.resolver || !name ? { isValid } : {}),
1199 errors: _formState.errors,
1200 });
1201
1202 options.shouldFocus &&
1203 !validationResult &&
1204 iterateFieldsByAction(
1205 _fields,
1206 _focusInput,
1207 name ? fieldNames : _names.mount,
1208 );
1209
1210 return validationResult;
1211 };
1212
1213 const getValues: UseFormGetValues<TFieldValues> = (
1214 fieldNames?:

Callers 15

setFieldValueFunction · 0.85
onChangeFunction · 0.85
AppFunction · 0.85
AppFunction · 0.85
AppFunction · 0.85
AppFunction · 0.85
AppFunction · 0.85
AppFunction · 0.85
AppFunction · 0.85
AppFunction · 0.85
ComponentFunction · 0.85
AppFunction · 0.85

Calls 4

executeBuiltInValidationFunction · 0.85
_setValidFunction · 0.85
iterateFieldsByActionFunction · 0.85

Tested by 14

AppFunction · 0.68
AppFunction · 0.68
AppFunction · 0.68
AppFunction · 0.68
AppFunction · 0.68
AppFunction · 0.68
AppFunction · 0.68
AppFunction · 0.68
ComponentFunction · 0.68
AppFunction · 0.68
onTriggerFunction · 0.68
ComponentFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…