mirror of
https://github.com/strapi/strapi.git
synced 2025-09-20 14:00:48 +00:00
refacto FormModal handleChange for CustomRadioGroup
This commit is contained in:
parent
86eed6b75d
commit
ffae9fa5e7
@ -10,6 +10,23 @@ import { Wrapper } from './components';
|
|||||||
const CustomRadioGroup = ({ intlLabel, name, onChange, radios, value }) => {
|
const CustomRadioGroup = ({ intlLabel, name, onChange, radios, value }) => {
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
|
|
||||||
|
const handleChange = e => {
|
||||||
|
let checked;
|
||||||
|
|
||||||
|
if (
|
||||||
|
name === 'multiple' ||
|
||||||
|
name === 'single' ||
|
||||||
|
name === 'createComponent' ||
|
||||||
|
name === 'repeatable'
|
||||||
|
) {
|
||||||
|
checked = e.target.value !== 'false';
|
||||||
|
} else {
|
||||||
|
checked = e.target.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
onChange({ target: { name, value: checked, type: 'radio' } });
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack size={2}>
|
<Stack size={2}>
|
||||||
<Text textColor="neutral800" htmlFor={name} small bold as="label">
|
<Text textColor="neutral800" htmlFor={name} small bold as="label">
|
||||||
@ -26,7 +43,7 @@ const CustomRadioGroup = ({ intlLabel, name, onChange, radios, value }) => {
|
|||||||
checked={radio.value === value}
|
checked={radio.value === value}
|
||||||
value={radio.value}
|
value={radio.value}
|
||||||
key={radio.value}
|
key={radio.value}
|
||||||
onChange={onChange}
|
onChange={handleChange}
|
||||||
type="radio"
|
type="radio"
|
||||||
/>
|
/>
|
||||||
<Box className="option" padding={4}>
|
<Box className="option" padding={4}>
|
||||||
|
@ -467,18 +467,6 @@ const FormModal = () => {
|
|||||||
|
|
||||||
if (namesThatCanResetToNullValue.includes(name) && value === '') {
|
if (namesThatCanResetToNullValue.includes(name) && value === '') {
|
||||||
val = null;
|
val = null;
|
||||||
} else if (
|
|
||||||
type === 'radio' &&
|
|
||||||
(name === 'multiple' ||
|
|
||||||
name === 'single' ||
|
|
||||||
name === 'createComponent' ||
|
|
||||||
name === 'repeatable')
|
|
||||||
) {
|
|
||||||
// eslint-disable-next-line no-unneeded-ternary
|
|
||||||
val = value === 'false' ? false : true;
|
|
||||||
|
|
||||||
// The boolean default accepts 3 different values
|
|
||||||
// This check has been added to allow a reset to null for the bool
|
|
||||||
} else {
|
} else {
|
||||||
val = value;
|
val = value;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user