Skip to content

Commit 999b6e4

Browse files
committed
Revert FilterLiveForm changes
1 parent 8871fba commit 999b6e4

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

packages/ra-core/src/form/FilterLiveForm.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ export const FilterLiveForm = (props: FilterLiveFormProps) => {
7676
resolver: finalResolver,
7777
...rest,
7878
});
79-
const { handleSubmit, getValues, reset, trigger, watch } = formContext;
79+
const { handleSubmit, getValues, reset, watch, formState } = formContext;
80+
const { isValid } = formState;
8081

8182
const hasJustBeenModifiedByUser = React.useRef(false);
8283

@@ -99,15 +100,17 @@ export const FilterLiveForm = (props: FilterLiveFormProps) => {
99100
}, [JSON.stringify(filterValues), getValues, reset]);
100101

101102
const onSubmit = (values: any): void => {
103+
// Do not call setFilters if the form is invalid
104+
if (!isValid) {
105+
return;
106+
}
102107
setFilters(mergeObjNotArray(filterValues, values));
103108
};
104109
const debouncedOnSubmit = useDebouncedEvent(onSubmit, debounce || 0);
105110

106111
// Submit the form on values change
107112
useEffect(() => {
108-
const { unsubscribe } = watch(async (values, { name }) => {
109-
// Trigger validation manually
110-
if (!(await trigger())) return;
113+
const { unsubscribe } = watch((values, { name }) => {
111114
// Check that the name is present to avoid setting filters when
112115
// watch was triggered by a reset
113116
if (name) {
@@ -123,7 +126,7 @@ export const FilterLiveForm = (props: FilterLiveFormProps) => {
123126
}
124127
});
125128
return () => unsubscribe();
126-
}, [watch, debouncedOnSubmit, trigger]);
129+
}, [watch, debouncedOnSubmit]);
127130

128131
const sourceContext = React.useMemo<SourceContextValue>(
129132
() => ({

0 commit comments

Comments
 (0)