Skip to content

Commit

Permalink
Fix FilterForm Submit
Browse files Browse the repository at this point in the history
Fixes #3731
  • Loading branch information
djhi committed Sep 25, 2019
1 parent 171e0d3 commit 0126076
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions packages/ra-ui-materialui/src/list/FilterForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const sanitizeRestProps = ({
dirtySinceLastSubmit,
dispatch,
displayedFilters,
filters,
filterValues,
handleSubmit,
hasSubmitErrors,
Expand Down Expand Up @@ -110,6 +111,7 @@ export class FilterForm extends Component {
<form
className={classnames(className, classes.form)}
{...sanitizeRestProps(rest)}
onSubmit={handleSubmit}
>
{this.getShownFilters().map(filterElement => (
<FilterFormInput
Expand All @@ -127,6 +129,11 @@ export class FilterForm extends Component {
}
}

const handleSubmit = event => {
event.preventDefault();
return false;
};

FilterForm.propTypes = {
resource: PropTypes.string.isRequired,
filters: PropTypes.arrayOf(PropTypes.node).isRequired,
Expand Down Expand Up @@ -169,9 +176,9 @@ const EnhancedFilterForm = props => {

return (
<Form
onSubmit={() => {}}
onSubmit={handleFinalFormSubmit}
initialValues={mergedInitialValuesWithDefaultValues}
render={formProps => (
render={() => (
<>
<FormSpy
subscription={FormSpySubscription}
Expand All @@ -182,13 +189,15 @@ const EnhancedFilterForm = props => {
props && props.setFilters(values);
}}
/>
<FilterForm classes={classes} {...formProps} {...rest} />
<FilterForm classes={classes} {...rest} />
</>
)}
/>
);
};

const handleFinalFormSubmit = () => {};

// Options to instruct the FormSpy that it should only listen to the values and pristine changes
const FormSpySubscription = { values: true, pristine: true };

Expand Down
2 changes: 1 addition & 1 deletion packages/ra-ui-materialui/src/list/FilterForm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('<FilterForm />', () => {
const filters = [
<TextInput source="title" label="Title" />,
<TextInput source="customer.name" label="Name" />,
]; // eslint-disable-line react/jsx-key
];
const displayedFilters = {
title: true,
'customer.name': true,
Expand Down

0 comments on commit 0126076

Please sign in to comment.