Skip to content
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

Fix null value support in inputs #8262

Merged
merged 32 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ff41d83
Fix null value support in inputs
slax57 Oct 13, 2022
a5d2720
remove useless format prop
slax57 Oct 13, 2022
39657d3
Add more tests
fzaninotto Oct 13, 2022
95e03aa
Handle undefined values, too
fzaninotto Oct 13, 2022
43df168
No need for format as it is already in useInput
fzaninotto Oct 13, 2022
83a5b76
Add more tests to SelectIInput
fzaninotto Oct 13, 2022
aafc64e
AutocompleteInput
slax57 Oct 14, 2022
c9e3879
extract FormInspector
slax57 Oct 14, 2022
41bd57f
DateInput
slax57 Oct 14, 2022
7b58efc
DateTimeInput
slax57 Oct 14, 2022
b8b5c9a
TimeInput
slax57 Oct 14, 2022
0928ac3
FileInput
slax57 Oct 14, 2022
9014786
ImageInput
slax57 Oct 14, 2022
ce222d4
SelectInput
slax57 Oct 14, 2022
2da082e
NullableBooleanInput
slax57 Oct 14, 2022
0f3fba7
RadioButtonGroupInput
slax57 Oct 14, 2022
ebe1575
RichTextInput
slax57 Oct 14, 2022
626cf59
move default parse to useInput
slax57 Oct 14, 2022
a66f05c
update sanitizeEmptyValues to handle null
slax57 Oct 14, 2022
ace29f3
[no ci] update doc
slax57 Oct 14, 2022
6aa5c03
add test about default parse in useInput
slax57 Oct 14, 2022
4af3f8f
rollback useless change
slax57 Oct 14, 2022
a1b89bc
remove unused parse in textinput
slax57 Oct 14, 2022
a418c55
Update Parse and format doc
fzaninotto Oct 14, 2022
748cd23
Fix input doc tranform tutorial
fzaninotto Oct 14, 2022
9d163d3
rewrite sanitizeEmptyValues doc
fzaninotto Oct 14, 2022
d1ff5f3
Remove useless defaultValue in SelectInput and AutocompleteInput
fzaninotto Oct 14, 2022
c1010cf
fix Inputs.md regarding sanitizeEmptyValues
slax57 Oct 17, 2022
e3b5d68
update sanitizeEmptyValues story and test
slax57 Oct 17, 2022
8c82a02
update sanitizeEmptyValues docs
slax57 Oct 17, 2022
413cd6b
document uncontrolled warning in custom inputs
slax57 Oct 17, 2022
ea943fe
fix linter warning
slax57 Oct 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions packages/ra-core/src/form/getFormInitialValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ export default function getFormInitialValues(
getValues(defaultValues, record),
record
);
// replace null values by empty string to avoid controlled/ uncontrolled input warning
Object.keys(finalInitialValues).forEach(key => {
if (finalInitialValues[key] === null) {
finalInitialValues[key] = '';
}
});
return finalInitialValues;
}

Expand Down
10 changes: 8 additions & 2 deletions packages/ra-core/src/form/useApplyInputDefaultValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@ export const useApplyInputDefaultValues = (
) => {
const { defaultValue, source } = props;
const record = useRecordContext(props);
const { getValues, resetField } = useFormContext();
const {
getValues,
resetField,
getFieldState,
formState,
} = useFormContext();
const recordValue = get(record, source);
const formValue = get(getValues(), source);
const { isDirty } = getFieldState(source, formState);

useEffect(() => {
if (defaultValue == null) return;
if (formValue == null && recordValue == null) {
if (formValue == null && recordValue == null && !isDirty) {
slax57 marked this conversation as resolved.
Show resolved Hide resolved
// special case for ArrayInput: since we use get(record, source),
// if source is like foo.23.bar, this effect will run.
// but we only want to set the default value for the subfield bar
Expand Down
Loading