UNPKG

@open-formulieren/formio-builder

Version:

An opinionated Formio webform builder for Open Forms

23 lines (22 loc) 1.64 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { useFormikContext } from 'formik'; import { useEffect } from 'react'; import { FormattedMessage, useIntl } from 'react-intl'; import { Checkbox } from '../../formio'; const SoftRequired = () => { var _a, _b, _c, _d; const intl = useIntl(); const { values, setFieldValue } = useFormikContext(); const isRequired = (_b = (_a = values === null || values === void 0 ? void 0 : values.validate) === null || _a === void 0 ? void 0 : _a.required) !== null && _b !== void 0 ? _b : false; const isSoftRequired = (_d = (_c = values === null || values === void 0 ? void 0 : values.openForms) === null || _c === void 0 ? void 0 : _c.softRequired) !== null && _d !== void 0 ? _d : false; // if the field is hard required, we must disable the soft required option, and // synchronize the softRequired to uncheck the option (if needed) useEffect(() => { if (isRequired && isSoftRequired) { setFieldValue('openForms.softRequired', false); } }, [setFieldValue, isRequired, isSoftRequired]); const tooltip = intl.formatMessage({ id: "8M403q", defaultMessage: [{ type: 0, value: "Soft required fields should be filled out, but empty values don't block the users' progress. Sometimes this is needed for legal reasons. A component cannot be hard and soft required at the same time." }] }); return (_jsx(Checkbox, { name: "openForms.softRequired", label: _jsx(FormattedMessage, { id: 'QL4SGQ', defaultMessage: [{ type: 0, value: "Soft required" }] }), tooltip: tooltip, disabled: isRequired })); }; export default SoftRequired;