-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
parse
function not returning data correctly for DateInput
component
#6573
Comments
That's a react-final-form feature:
https://final-form.org/docs/react-final-form/types/FieldProps#allownull You can disable it with |
The |
Also, the problem isn't that I want the INPUT to accept null values. I want to send the null value to the |
Reopening - there is something else at stake here. A simple parse funciton like |
After further research, final-form/react-final-form#383 I don't know if we can solve it in react-admin. |
Unit test case reproducing the bug: it('should accept a parse function returning null', () => {
let formApi;
const { getByLabelText } = render(
<Form
onSubmit={jest.fn()}
initialValues={{ publishedAt: new Date('2021-09-11') }}
render={({ form }) => {
formApi = form;
return <DateInput resource="posts" source="publishedAt" parse={val => null} />;
}}
/>
);
const input = getByLabelText(
'resources.posts.fields.publishedAt'
) as HTMLInputElement;
expect(input.value).toBe('2021-09-11');
expect(formApi.getState().values.publishedAt).toEqual(
new Date('2021-09-11')
);
fireEvent.change(input, {
target: { value: '' },
});
fireEvent.blur(input);
expect(formApi.getState().values.publishedAt).toBeNull();
}); |
I will take a look into it when possible. Probably there's an workaround to allow that. |
i have this problem too.
so i used customToolbar temporarily.
|
@djhi, could this be closed? |
Yes, thanks |
What you were expecting:
While trying to use the
DateInput
component, I observed that it was returning an empty string for the date, however I needed it to returnnull
so I could send it through thedataProvider
. Then I used theparse
property ofDateInput
to make it returnnull
when the field were empty.What happened instead:
When using the parsing function that returns the data I wanted (
null
when the field is empty), it is returning an empty string""
to the fieldrejected_at
.Steps to reproduce:
/posts/1
which is where I mocked therejected_at
(insidedata.tsx
) field, in the post with id 1.Rejected at
field.rejected_at
field is an""
and notnull
.Related code:
Parsing function located at
PostEdit.tsx
:Other information:
I managed to bypass the problem using it along with
format
property and passing the original default code for theformat
function (format = getStringFromDate
at the parameters) fromDateInput.tsx
, but instead of returning""
at the firstif
, I have changed it to returnvalue
. I passed it to theformat
function and then it returned thenull
value that I needed.File
ra-ui-materialui/src/input/DateInput.tsx
:This behavior should not happen as the
parse
function was supposed to transform theinput -> record
as the documentation mentions. Theformat
function is somehow influencing the transformation.Environment
The text was updated successfully, but these errors were encountered: