@open-formulieren/formio-builder
Version:
An opinionated Formio webform builder for Open Forms
83 lines (82 loc) • 5.99 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ComparisonValueInput = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_intl_1 = require("react-intl");
const builder_1 = require("../../components/builder");
const messages_1 = require("../../components/builder/messages");
const formio_1 = require("../../components/formio");
const errors_1 = require("../../utils/errors");
/**
* Form to configure a Formio 'number' type component.
*/
const EditForm = () => {
const intl = (0, react_intl_1.useIntl)();
const [isKeyManuallySetRef, generatedKey] = (0, builder_1.useDeriveComponentKey)();
const { hasAnyError } = (0, errors_1.useErrorChecker)();
builder_1.Validate.useManageValidatorsTranslations(['required', 'min', 'max']);
return ((0, jsx_runtime_1.jsxs)(formio_1.Tabs, { children: [(0, jsx_runtime_1.jsxs)(formio_1.TabList, { children: [(0, jsx_runtime_1.jsx)(builder_1.BuilderTabs.Basic, { hasErrors: hasAnyError('label', 'key', 'description', 'tooltip', 'showInSummary', 'showInEmail', 'showInPDF', 'hidden', 'clearOnHide', 'isSensitiveData', 'defaultValue', 'decimalLimit', 'allowNegative', 'suffix') }), (0, jsx_runtime_1.jsx)(builder_1.BuilderTabs.Advanced, { hasErrors: hasAnyError('conditional') }), (0, jsx_runtime_1.jsx)(builder_1.BuilderTabs.Validation, { hasErrors: hasAnyError('validate') }), (0, jsx_runtime_1.jsx)(builder_1.BuilderTabs.Registration, { hasErrors: hasAnyError('registration') }), (0, jsx_runtime_1.jsx)(builder_1.BuilderTabs.Prefill, { hasErrors: hasAnyError('prefill') }), (0, jsx_runtime_1.jsx)(builder_1.BuilderTabs.Translations, { hasErrors: hasAnyError('openForms.translations') })] }), (0, jsx_runtime_1.jsxs)(formio_1.TabPanel, { children: [(0, jsx_runtime_1.jsx)(builder_1.Label, {}), (0, jsx_runtime_1.jsx)(builder_1.Key, { isManuallySetRef: isKeyManuallySetRef, generatedValue: generatedKey }), (0, jsx_runtime_1.jsx)(builder_1.Description, {}), (0, jsx_runtime_1.jsx)(builder_1.Tooltip, {}), (0, jsx_runtime_1.jsx)(builder_1.Suffix, {}), (0, jsx_runtime_1.jsx)(builder_1.PresentationConfig, {}), (0, jsx_runtime_1.jsx)(builder_1.Hidden, {}), (0, jsx_runtime_1.jsx)(builder_1.ClearOnHide, {}), (0, jsx_runtime_1.jsx)(builder_1.IsSensitiveData, {}), (0, jsx_runtime_1.jsx)(DefaultValue, {}), (0, jsx_runtime_1.jsx)(DecimalLimit, {}), (0, jsx_runtime_1.jsx)(AllowNegative, {})] }), (0, jsx_runtime_1.jsx)(formio_1.TabPanel, { children: (0, jsx_runtime_1.jsx)(builder_1.SimpleConditional, {}) }), (0, jsx_runtime_1.jsxs)(formio_1.TabPanel, { children: [(0, jsx_runtime_1.jsx)(builder_1.Validate.Required, {}), (0, jsx_runtime_1.jsx)(builder_1.Validate.ValidatorPluginSelect, {}), (0, jsx_runtime_1.jsx)(builder_1.Validate.Min, {}), (0, jsx_runtime_1.jsx)(builder_1.Validate.Max, {}), (0, jsx_runtime_1.jsx)(builder_1.Validate.ValidationErrorTranslations, {})] }), (0, jsx_runtime_1.jsx)(formio_1.TabPanel, { children: (0, jsx_runtime_1.jsx)(builder_1.Registration.RegistrationAttributeSelect, {}) }), (0, jsx_runtime_1.jsx)(formio_1.TabPanel, { children: (0, jsx_runtime_1.jsx)(builder_1.Prefill.PrefillConfiguration, {}) }), (0, jsx_runtime_1.jsx)(formio_1.TabPanel, { children: (0, jsx_runtime_1.jsx)(builder_1.Translations.ComponentTranslations, { propertyLabels: {
label: intl.formatMessage(messages_1.LABELS.label),
description: intl.formatMessage(messages_1.LABELS.description),
tooltip: intl.formatMessage(messages_1.LABELS.tooltip),
suffix: intl.formatMessage({ id: "oWJX5K", defaultMessage: [{ type: 0, value: "Suffix (e.g. m\u00B2)" }] }),
} }) })] }));
};
EditForm.defaultValues = {
// basic tab
label: '',
key: '',
description: '',
tooltip: '',
showInSummary: true,
showInEmail: false,
showInPDF: true,
hidden: false,
clearOnHide: true,
isSensitiveData: false,
defaultValue: null,
decimalLimit: undefined,
allowNegative: false,
suffix: '',
// Advanced tab
conditional: {
show: undefined,
when: '',
eq: '',
},
// Validation tab
validate: {
required: false,
plugins: [],
min: undefined,
max: undefined,
},
translatedErrors: {},
// Registration tab
registration: {
attribute: '',
},
prefill: {
plugin: '',
attribute: '',
identifierRole: 'main',
},
};
const DefaultValue = () => {
const intl = (0, react_intl_1.useIntl)();
const tooltip = intl.formatMessage({ id: "FffJxu", defaultMessage: [{ type: 0, value: "This will be the initial value for this field before user interaction." }] });
return ((0, jsx_runtime_1.jsx)(formio_1.NumberField, { name: "defaultValue", label: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, Object.assign({}, messages_1.LABELS.defaultValue)), tooltip: tooltip }));
};
const DecimalLimit = () => {
const intl = (0, react_intl_1.useIntl)();
const tooltip = intl.formatMessage({ id: "m20av3", defaultMessage: [{ type: 0, value: "The maximum number of decimal places." }] });
return ((0, jsx_runtime_1.jsx)(formio_1.NumberField, { name: "decimalLimit", label: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: 'BvRBef', defaultMessage: [{ type: 0, value: "Decimal places" }] }), tooltip: tooltip }));
};
const AllowNegative = () => {
const intl = (0, react_intl_1.useIntl)();
const tooltip = intl.formatMessage({ id: "3LEg1l", defaultMessage: [{ type: 0, value: "Allow negative values." }] });
return ((0, jsx_runtime_1.jsx)(formio_1.Checkbox, { name: "allowNegative", label: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: 'E8Tuiq', defaultMessage: [{ type: 0, value: "Allow negative values" }] }), tooltip: tooltip }));
};
const ComparisonValueInput = formio_1.NumberField;
exports.ComparisonValueInput = ComparisonValueInput;
exports.default = EditForm;