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 [fieldSettings, setFieldSettings] = useState({});
|
||||
|
||||
const canSubmit = fieldName && !isEmpty(fieldSettings);
|
||||
const canSubmit = fieldName && !isEmpty(fieldSettings) && (fieldSettings.isValid !== false);
|
||||
const defaultType = dateSettings.dateTypes[0].value;
|
||||
const defaultFormat = dateSettings.dateFormats[defaultType][0];
|
||||
|
||||
|
@@ -4,6 +4,7 @@ import {
|
||||
Button,
|
||||
ToggleControl,
|
||||
} from '@wordpress/components';
|
||||
import { isEmpty } from 'lodash';
|
||||
import PropTypes from 'prop-types';
|
||||
import MailPoet from 'mailpoet';
|
||||
import CustomFieldDelete from '../custom_field_delete.jsx';
|
||||
@@ -26,12 +27,11 @@ const CustomFieldSettings = ({
|
||||
mandatory: localMandatory,
|
||||
isChecked: localIsChecked,
|
||||
checkboxLabel: localCheckboxLabel,
|
||||
isValid: !isEmpty(localCheckboxLabel),
|
||||
}), [localMandatory, localIsChecked, localCheckboxLabel]);
|
||||
|
||||
useEffect(() => {
|
||||
if (onChange) {
|
||||
onChange(localData);
|
||||
}
|
||||
onChange(localData);
|
||||
}, [localData, onChange]);
|
||||
|
||||
return (
|
||||
@@ -101,7 +101,7 @@ CustomFieldSettings.defaultProps = {
|
||||
checkboxLabel: '',
|
||||
isDeleting: false,
|
||||
onCustomFieldDelete: null,
|
||||
onChange: null,
|
||||
onChange: () => {},
|
||||
};
|
||||
|
||||
export default CustomFieldSettings;
|
||||
|
Reference in New Issue
Block a user