Skip to content

Commit

Permalink
Apply review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
djhi committed Jun 12, 2024
1 parent e7f1ec0 commit 8b03446
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,24 @@ export const SimpleFormIterator = (props: SimpleFormIteratorProps) => {
} = props;
const [confirmIsOpen, setConfirmIsOpen] = useState<boolean>(false);
const { append, fields, move, remove, replace } = useArrayInput(props);
const { resetField, trigger } = useFormContext();
const { resetField, trigger, getValues } = useFormContext();
const translate = useTranslate();
const record = useRecordContext(props);
const initialDefaultValue = useRef({});

const removeField = useCallback(
(index: number) => {
remove(index);
// Trigger validation on the Array to avoid ghost errors.
// Otherwise, validation errors on removed fields might still be displayed
trigger(source);
const isScalarArray = getValues(source).every(
(value: any) => typeof value !== 'object'
);
if (isScalarArray) {
// Trigger validation on the Array to avoid ghost errors.
// Otherwise, validation errors on removed fields might still be displayed
trigger(source);
}
},
[remove, trigger, source]
[remove, trigger, source, getValues]
);

if (fields.length > 0) {
Expand Down

0 comments on commit 8b03446

Please sign in to comment.