Prevent saving checkbox without label

[MAILPOET-2652]
This commit is contained in:
Pavel Dohnal
2020-01-23 12:34:10 +01:00
committed by Jack Kitterhing
parent 182fec1d3b
commit f606514d8f
2 changed files with 5 additions and 5 deletions

View File

@@ -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];

View File

@@ -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;