UNPKG

@open-formulieren/formio-builder

Version:

An opinionated Formio webform builder for Open Forms

38 lines (37 loc) 2.08 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const jsx_runtime_1 = require("react/jsx-runtime"); const formik_1 = require("formik"); const react_1 = require("react"); const react_intl_1 = require("react-intl"); const useAsync_1 = __importDefault(require("react-use/esm/useAsync")); const select_1 = __importDefault(require("../../../components/formio/select")); const context_1 = require("../../../context"); function isAttributeOptions(options) { return options !== undefined; } /** * Fetch the available validator plugins and display them in a multiselect. * * This requires an async function `getRegistrationAttributes` to be provided to the * BuilderContext which is responsible for retrieving the list of available plugins. * * If a fetch error occurs, it is thrown during rendering - you should provide your * own error boundary to catch this. */ const RegistrationAttributeSelect = () => { const intl = (0, react_intl_1.useIntl)(); const { values } = (0, formik_1.useFormikContext)(); const { getRegistrationAttributes } = (0, react_1.useContext)(context_1.BuilderContext); const { value: options, loading, error, } = (0, useAsync_1.default)(async () => await getRegistrationAttributes(values.type || ''), []); if (error) { throw error; } const tooltip = intl.formatMessage({ id: "fT6Gtt", defaultMessage: [{ type: 0, value: "Save the value as this attribute in the registration backend system." }] }); const _options = isAttributeOptions(options) ? options : []; return ((0, jsx_runtime_1.jsx)(select_1.default, { name: "registration.attribute", label: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: 'EacF3m', defaultMessage: [{ type: 0, value: "Registration attribute" }] }), tooltip: tooltip, isLoading: loading, isClearable: true, options: _options, valueProperty: "id" })); }; exports.default = RegistrationAttributeSelect;