@formality-ui/react 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -149,6 +149,7 @@ function Form({
149
149
  record,
150
150
  autoSave = false,
151
151
  debounce: debounceMs = 1e3,
152
+ mode,
152
153
  validate
153
154
  }) {
154
155
  const providerConfig = useConfigContext();
@@ -166,7 +167,7 @@ function Form({
166
167
  return core.resolveAllInitialValues(config, mergedInputs, record ?? {});
167
168
  }, [config, mergedInputs, record]);
168
169
  const methods = reactHookForm.useForm({
169
- mode: "onChange",
170
+ mode: mode ?? "onChange",
170
171
  defaultValues,
171
172
  values: record
172
173
  });
@@ -406,9 +407,20 @@ function Form({
406
407
  if (!validationsComplete || executionVersionRef.current !== executionVersion) {
407
408
  return;
408
409
  }
409
- for (const fieldName of changedFields) {
410
- const fieldState = methods.getFieldState(fieldName);
411
- if (fieldState.error) {
410
+ const changedArray = [...changedFields];
411
+ if (changedArray.length > 0) {
412
+ const changedValid = await methods.trigger(changedArray);
413
+ if (executionVersionRef.current !== executionVersion) {
414
+ return;
415
+ }
416
+ if (!changedValid) {
417
+ return;
418
+ }
419
+ const changedValidationsComplete = await waitForFieldValidation(
420
+ changedArray,
421
+ executionVersion
422
+ );
423
+ if (!changedValidationsComplete || executionVersionRef.current !== executionVersion) {
412
424
  return;
413
425
  }
414
426
  }