I've got an Edit form using react-admin, and I'm trying to figure out how to add a button to clear some of the fields on click.
The relevant chunk of form:
const ProfileEdit = withDataProvider((
{...props}:{
record: ProfileRecord,
dataProvider:DataProvider,
dispatch:DispatchFunction
},
) => {
const {dataProvider, dispatch, ...rest} = props;
return (
<Edit {...rest}>
<TabbedForm >
<FormTab label='Profile'>
<TextInput source='message'/>
<DateTimeInput source='start'/>
<DateTimeInput source='expiry'/>
<FormDataConsumer>
{({ formData }) =>
<Button onClick={()=>{clearFields(formData)}}>Clear Fields</Button>
}
</FormDataConsumer>
</FormTab>
</TabbedForm>
</Edit>
);
});
And the clear function:
const clearFields = (data) => {
data.message = null;
data.start = null;
data.expiry = null;
return null;
};
Unfortunately, this isn't accomplishing anything.
Is this a matter of setting up my onClick better, or am I going about this all wrong?