Update form state inside onChange based on which checkbox the user has selected #9151
-
Hey folks, I have to take an action based on which checkbox the user has chosen and then update the form based on that. So I have a form that looks like this: Then, whenever the user selects, e.g. "Manage" in case it has "View" selected before, I need to deselect "View" because with "Manage" user already has "View" right. I think you know what I mean. I have tried to make use of
Any help would be very welcome! Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
@RSchneider94 : The logic can be simplified by just using custom "onChange" for CheckboxGroup component. For example:
Working demo: https://codesandbox.io/s/nervous-saha-80b1ho?file=/src/App.tsx |
Beta Was this translation helpful? Give feedback.
-
Just to be sure, when creating an input component and using a custom 'onChnage; we need to use the const handleChange: AntInputNumberProps['onChange'] = (val: any) => {
if (isNaN(Number(val))) {
field.onChange(null);
return;
}
field.onChange(+val);
}; Like this? |
Beta Was this translation helpful? Give feedback.
@RSchneider94 : The logic can be simplified by just using custom "onChange" for CheckboxGroup component.
For example:
Working demo: https://codesandbox.io/s/nervous-saha-80b1ho?file=/src/App.tsx