diff --git a/packages/ra-core/src/form/FormDataConsumer.tsx b/packages/ra-core/src/form/FormDataConsumer.tsx index bbb4a82598e..519e3ea80ce 100644 --- a/packages/ra-core/src/form/FormDataConsumer.tsx +++ b/packages/ra-core/src/form/FormDataConsumer.tsx @@ -56,7 +56,7 @@ export const FormDataConsumerView = (props: Props) => { let ret; // If we have an index, we are in an iterator like component (such as the SimpleFormIterator) - if (typeof index !== 'undefined') { + if (typeof index !== 'undefined' && source) { scopedFormData = get(formData, source); getSource = (scopedSource: string) => { getSourceHasBeenCalled = true; diff --git a/packages/ra-core/src/form/FormGroupsContext.tsx b/packages/ra-core/src/form/FormGroupsContext.tsx index d01af9d7274..5a1f3cc9a8d 100644 --- a/packages/ra-core/src/form/FormGroupsContext.tsx +++ b/packages/ra-core/src/form/FormGroupsContext.tsx @@ -1,8 +1,8 @@ import { createContext } from 'react'; -export const FormGroupsContext = createContext( - undefined -); +export const FormGroupsContext = createContext< + FormGroupsContextValue | undefined +>(undefined); export type FormGroupSubscriber = () => void; diff --git a/packages/ra-core/src/form/choices/ChoicesContext.ts b/packages/ra-core/src/form/choices/ChoicesContext.ts index f7a42996080..3421d93bba5 100644 --- a/packages/ra-core/src/form/choices/ChoicesContext.ts +++ b/packages/ra-core/src/form/choices/ChoicesContext.ts @@ -6,7 +6,9 @@ import { FilterPayload, RaRecord, SortPayload } from '../../types'; * * Use the useChoicesContext() hook to read the context. */ -export const ChoicesContext = createContext(undefined); +export const ChoicesContext = createContext( + undefined +); export type ChoicesContextValue = { allChoices: RecordType[]; diff --git a/packages/ra-core/src/form/getFormInitialValues.ts b/packages/ra-core/src/form/getFormInitialValues.ts index 565899792a1..a6ae3121a05 100644 --- a/packages/ra-core/src/form/getFormInitialValues.ts +++ b/packages/ra-core/src/form/getFormInitialValues.ts @@ -3,7 +3,7 @@ import { RaRecord } from '../types'; export default function getFormInitialValues( defaultValues: DefaultValue, - record: Partial + record?: Partial ) { const finalInitialValues = merge( {}, diff --git a/packages/ra-core/src/form/getSimpleValidationResolver.ts b/packages/ra-core/src/form/getSimpleValidationResolver.ts index 3dfab345e05..4cf693fd5c5 100644 --- a/packages/ra-core/src/form/getSimpleValidationResolver.ts +++ b/packages/ra-core/src/form/getSimpleValidationResolver.ts @@ -4,7 +4,7 @@ import { ValidationErrorMessageWithArgs } from './validate'; // Flattening an object into path keys: // https://github.com/lodash/lodash/issues/2240#issuecomment-418820848 -export const flattenErrors = (obj, path = []) => +export const flattenErrors = (obj, path: string[] = []) => !_.isObject(obj) ? { [path.join('.')]: obj } : _.reduce( diff --git a/packages/ra-core/src/form/setSubmissionErrors.ts b/packages/ra-core/src/form/setSubmissionErrors.ts index c21d38356b3..155c8a0962c 100644 --- a/packages/ra-core/src/form/setSubmissionErrors.ts +++ b/packages/ra-core/src/form/setSubmissionErrors.ts @@ -39,7 +39,7 @@ export const setSubmissionErrors = ( }); }); }; - const setErrorFromObject = (errors: any, rootPath: string) => { + const setErrorFromObject = (errors: FieldValues, rootPath: string) => { Object.entries(errors).forEach(([name, error]) => { if (typeof error === 'object') { setErrorFromObject(error, `${rootPath}${name}.`); diff --git a/packages/ra-core/src/form/useApplyInputDefaultValues.ts b/packages/ra-core/src/form/useApplyInputDefaultValues.ts index fdf927d1f93..eca673f5405 100644 --- a/packages/ra-core/src/form/useApplyInputDefaultValues.ts +++ b/packages/ra-core/src/form/useApplyInputDefaultValues.ts @@ -8,7 +8,9 @@ import { InputProps } from './useInput'; * This hook updates the input default value whenever the record changes * It applies either the record value if it has one or the defaultValue if it was specified */ -export const useApplyInputDefaultValues = (props: Partial) => { +export const useApplyInputDefaultValues = ( + props: Partial & { source: string } +) => { const { defaultValue, source } = props; const record = useRecordContext(props); const { getValues, resetField } = useFormContext(); diff --git a/packages/ra-core/src/form/useAugmentedForm.ts b/packages/ra-core/src/form/useAugmentedForm.ts index 5bfed0b974a..aa15260e5d7 100644 --- a/packages/ra-core/src/form/useAugmentedForm.ts +++ b/packages/ra-core/src/form/useAugmentedForm.ts @@ -98,7 +98,7 @@ export const useAugmentedForm = (props: UseAugmentedFormProps) => { // warn when unsaved change useWarnWhenUnsavedChanges( - warnWhenUnsavedChanges, + Boolean(warnWhenUnsavedChanges), formRootPathname, form.control ); diff --git a/packages/ra-core/src/form/useFormGroup.ts b/packages/ra-core/src/form/useFormGroup.ts index da85384e81f..3eaae18656d 100644 --- a/packages/ra-core/src/form/useFormGroup.ts +++ b/packages/ra-core/src/form/useFormGroup.ts @@ -13,7 +13,7 @@ type FieldState = { }; type FormGroupState = { - errors: object; + errors?: object; isDirty: boolean; isTouched: boolean; isValid: boolean; @@ -128,7 +128,7 @@ export const useFormGroup = (name: string): FormGroupState => { export const getFormGroupState = ( fieldStates: FieldState[] ): FormGroupState => { - return fieldStates.reduce( + return fieldStates.reduce( (acc, fieldState) => { let errors = acc.errors || {}; diff --git a/packages/ra-core/src/form/useSuggestions.ts b/packages/ra-core/src/form/useSuggestions.ts index f42234e4255..3ad791c8d61 100644 --- a/packages/ra-core/src/form/useSuggestions.ts +++ b/packages/ra-core/src/form/useSuggestions.ts @@ -174,7 +174,7 @@ export const getSuggestionsFactory = ({ getChoiceText: (choice: any) => string | ReactElement; getChoiceValue: (choice: any) => string; }) => filter => { - let suggestions = []; + let suggestions: any[] = []; // if an item is selected and matches the filter if ( selectedItem &&