dirk-cfx-react 1.1.17 → 1.1.18

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.js CHANGED
@@ -2038,6 +2038,15 @@ function createFormStore(initialValues, validationRules, onSubmit) {
2038
2038
  state.onSubmit(get());
2039
2039
  }
2040
2040
  },
2041
+ getInputProps: (path) => {
2042
+ return {
2043
+ value: getNested(get().values, path) ?? "",
2044
+ error: get().errors[path],
2045
+ onChange: (e) => {
2046
+ get().setValue(path, e.target.value, { validate: true });
2047
+ }
2048
+ };
2049
+ },
2041
2050
  resetChangeCount: () => {
2042
2051
  changed.clear();
2043
2052
  set({ changedFields: [], changedCount: 0, partialChanged: {} });
@@ -2045,6 +2054,8 @@ function createFormStore(initialValues, validationRules, onSubmit) {
2045
2054
  setInitialValues: (newInitialValues) => set({ initialValues: newInitialValues }),
2046
2055
  setValue: (path, value, options) => {
2047
2056
  const state = get();
2057
+ const currentValue = getNested(state.values, path);
2058
+ if (currentValue === value) return;
2048
2059
  const currentValues = state.values;
2049
2060
  const newValues = setNested(currentValues, path, value);
2050
2061
  const oldValue = getNested(state.initialValues, path);
@@ -2059,22 +2070,27 @@ function createFormStore(initialValues, validationRules, onSubmit) {
2059
2070
  changed.delete(path);
2060
2071
  newPartial = deleteNested(newPartial, path);
2061
2072
  }
2073
+ const newSize = changed.size;
2074
+ const changedFields = newSize !== state.changedCount ? Array.from(changed) : state.changedFields;
2062
2075
  set({
2063
2076
  values: newValues,
2064
2077
  partialChanged: newPartial,
2065
2078
  canBack: history.length > 0,
2066
2079
  canForward: false,
2067
- changedFields: Array.from(changed),
2068
- changedCount: changed.size
2080
+ changedFields,
2081
+ changedCount: newSize
2069
2082
  });
2070
2083
  if (!options?.validate) return;
2071
2084
  const rule = flatRules[path];
2072
2085
  if (!rule) return;
2073
- Promise.resolve(runRule(rule, value, newValues)).then((error2) => {
2074
- if (error2)
2075
- set((s) => ({ errors: setNested(s.errors, path, error2) }));
2076
- else
2077
- set((s) => ({ errors: deleteNested(s.errors, path) }));
2086
+ queueMicrotask(() => {
2087
+ runRule(rule, value, newValues).then((error2) => {
2088
+ if (error2) {
2089
+ set((s) => ({ errors: setNested(s.errors, path, error2) }));
2090
+ } else {
2091
+ set((s) => ({ errors: deleteNested(s.errors, path) }));
2092
+ }
2093
+ });
2078
2094
  });
2079
2095
  },
2080
2096
  setError: (path, message) => set((s) => ({ errors: setNested(s.errors, path, message) })),