@open-formulieren/formio-builder
Version:
An opinionated Formio webform builder for Open Forms
38 lines (37 loc) • 2.02 kB
JavaScript
;
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 context_1 = require("../../../context");
const select_1 = __importDefault(require("../../formio/select"));
function isValidatorOptions(options) {
return options !== undefined;
}
/**
* Fetch the available validator plugins and display them in a multiselect.
*
* This requires an async function `getValidatorPlugins` 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 ValidatorPluginSelect = () => {
const intl = (0, react_intl_1.useIntl)();
const { values } = (0, formik_1.useFormikContext)();
const { getValidatorPlugins } = (0, react_1.useContext)(context_1.BuilderContext);
const { value: options, loading, error, } = (0, useAsync_1.default)(async () => await getValidatorPlugins(values.type || ''), []);
if (error) {
throw error;
}
const tooltip = intl.formatMessage({ id: "UGLnLd", defaultMessage: [{ type: 0, value: "Select the plugin(s) to use for the validation functionality." }] });
const _options = isValidatorOptions(options) ? options : [];
return ((0, jsx_runtime_1.jsx)(select_1.default, { name: "validate.plugins", label: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: 'UCGSib', defaultMessage: [{ type: 0, value: "Plugin(s)" }] }), tooltip: tooltip, isLoading: loading, isMulti: true, isClearable: true, options: _options, valueProperty: "id" }));
};
exports.default = ValidatorPluginSelect;