diff --git a/assets/js/src/form_editor/blocks/custom_checkbox/custom_field_settings.jsx b/assets/js/src/form_editor/blocks/custom_checkbox/custom_field_settings.jsx index e385b530a7..07acabab75 100644 --- a/assets/js/src/form_editor/blocks/custom_checkbox/custom_field_settings.jsx +++ b/assets/js/src/form_editor/blocks/custom_checkbox/custom_field_settings.jsx @@ -10,8 +10,12 @@ const CustomFieldSettings = ({ mandatory, isSaving, onSave, + isChecked, + checkboxLabel, }) => { const [localMandatory, setLocalMandatory] = useState(mandatory); + const [localIsChecked, setLocalIsChecked] = useState(isChecked); + const [localCheckboxLabel, setLocalCheckboxLabel] = useState(checkboxLabel); return (
@@ -20,6 +24,8 @@ const CustomFieldSettings = ({ isDefault onClick={() => onSave({ mandatory: localMandatory, + isChecked: localIsChecked, + checkboxLabel: localCheckboxLabel, })} isBusy={isSaving} disabled={isSaving} @@ -32,6 +38,17 @@ const CustomFieldSettings = ({ checked={localMandatory} onChange={setLocalMandatory} /> +
+ setLocalIsChecked(!!event.target.checked)} + /> + setLocalCheckboxLabel(event.target.value)} + /> +
); }; @@ -40,11 +57,15 @@ CustomFieldSettings.propTypes = { mandatory: PropTypes.bool, onSave: PropTypes.func.isRequired, isSaving: PropTypes.bool, + isChecked: PropTypes.bool, + checkboxLabel: PropTypes.string, }; CustomFieldSettings.defaultProps = { mandatory: false, isSaving: false, + isChecked: false, + checkboxLabel: '', }; export default CustomFieldSettings; diff --git a/assets/js/src/form_editor/blocks/custom_checkbox/edit.jsx b/assets/js/src/form_editor/blocks/custom_checkbox/edit.jsx index a9f7829b7d..ceb631b421 100644 --- a/assets/js/src/form_editor/blocks/custom_checkbox/edit.jsx +++ b/assets/js/src/form_editor/blocks/custom_checkbox/edit.jsx @@ -47,15 +47,25 @@ const CustomCheckboxEdit = ({ attributes, setAttributes }) => { saveCustomField({ customFieldId: attributes.customFieldId, data: { params: { required: params.mandatory ? '1' : undefined, + values: [{ + is_checked: params.isChecked ? '1' : undefined, + value: params.checkboxLabel, + }], }, }, onFinish: () => setAttributes({ mandatory: params.mandatory, + values: [{ + isChecked: params.isChecked, + name: params.checkboxLabel, + }], }), })} /> @@ -74,25 +84,6 @@ const CustomCheckboxEdit = ({ attributes, setAttributes }) => { checked={!attributes.hideLabel} onChange={(hideLabel) => (setAttributes({ hideLabel: !hideLabel }))} /> - setAttributes({ - values: [{ - name: getCheckboxLabel(), - checked: !!event.target.checked, - }], - })} - /> - setAttributes({ - values: [{ - name: event.target.value, - checked: isChecked(), - }], - })} - />