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

View File

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