fieldArray move method not working when shouldUnregister is true #12678
Unanswered
roxana-ahmadi
asked this question in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
i have an dnd using react hook form field array, in the handleDrop im using move function from useFieldArray, it dosent work properly and it sets the dragged item value to its default value! shouldUnregister is causing move function to not updating fieldArray fields, i would appreciate if you help.
here is my code
`const defaultSingleValues: IDiscountFormFields = {
mode: 'single', // Default to 'single' mode
description: '5555',
discountType: 'percentage', // Default type
percentDiscount: [{ ratePercent: 0, minOrderAmount: 0 }], // Default percentage discount
fixedDiscount: [{ amount: 0, minOrderAmount: 0 }], // Default fixed discount
startDate: '',
endDate: '',
usable: 'noLimit',
usageNumber: undefined,
usageLimit: 'noLimit',
categories: [],
products: [],
// Single Mode Defaults
discountCode: '',
notification: null,
targetUsers: 'all',
users: [],
};
const methods = useForm({
defaultValues: defaultSingleValues,
shouldUnregister: true,
});
} = useFieldArray({
control,
name: 'percentDiscount',
shouldUnregister: false,
});
};
`
Beta Was this translation helpful? Give feedback.
All reactions