Prevent saving checkbox without label
[MAILPOET-2652]
This commit is contained in:
committed by
Jack Kitterhing
parent
182fec1d3b
commit
f606514d8f
@@ -47,7 +47,7 @@ const AddCustomFieldForm = ({ dateSettings, onSubmit }) => {
|
|||||||
const [fieldName, setFieldName] = useState(null);
|
const [fieldName, setFieldName] = useState(null);
|
||||||
const [fieldSettings, setFieldSettings] = useState({});
|
const [fieldSettings, setFieldSettings] = useState({});
|
||||||
|
|
||||||
const canSubmit = fieldName && !isEmpty(fieldSettings);
|
const canSubmit = fieldName && !isEmpty(fieldSettings) && (fieldSettings.isValid !== false);
|
||||||
const defaultType = dateSettings.dateTypes[0].value;
|
const defaultType = dateSettings.dateTypes[0].value;
|
||||||
const defaultFormat = dateSettings.dateFormats[defaultType][0];
|
const defaultFormat = dateSettings.dateFormats[defaultType][0];
|
||||||
|
|
||||||
|
@@ -4,6 +4,7 @@ import {
|
|||||||
Button,
|
Button,
|
||||||
ToggleControl,
|
ToggleControl,
|
||||||
} from '@wordpress/components';
|
} from '@wordpress/components';
|
||||||
|
import { isEmpty } from 'lodash';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import MailPoet from 'mailpoet';
|
import MailPoet from 'mailpoet';
|
||||||
import CustomFieldDelete from '../custom_field_delete.jsx';
|
import CustomFieldDelete from '../custom_field_delete.jsx';
|
||||||
@@ -26,12 +27,11 @@ const CustomFieldSettings = ({
|
|||||||
mandatory: localMandatory,
|
mandatory: localMandatory,
|
||||||
isChecked: localIsChecked,
|
isChecked: localIsChecked,
|
||||||
checkboxLabel: localCheckboxLabel,
|
checkboxLabel: localCheckboxLabel,
|
||||||
|
isValid: !isEmpty(localCheckboxLabel),
|
||||||
}), [localMandatory, localIsChecked, localCheckboxLabel]);
|
}), [localMandatory, localIsChecked, localCheckboxLabel]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (onChange) {
|
onChange(localData);
|
||||||
onChange(localData);
|
|
||||||
}
|
|
||||||
}, [localData, onChange]);
|
}, [localData, onChange]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -101,7 +101,7 @@ CustomFieldSettings.defaultProps = {
|
|||||||
checkboxLabel: '',
|
checkboxLabel: '',
|
||||||
isDeleting: false,
|
isDeleting: false,
|
||||||
onCustomFieldDelete: null,
|
onCustomFieldDelete: null,
|
||||||
onChange: null,
|
onChange: () => {},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default CustomFieldSettings;
|
export default CustomFieldSettings;
|
||||||
|
Reference in New Issue
Block a user