-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathFormBuilder.js
68 lines (61 loc) · 3.2 KB
/
FormBuilder.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { Formio } from './Formio';
import Builders from './builders';
import Form from './Form';
export default class FormBuilder extends Form {
/**
* @typedef FormBuilderOptions
* @property {string[]} [disabled] - An array of "keys" of components that should be disabled within the form builder. Example: ['firstName', 'lastName']
* @property {boolean} [noNewEdit] - When set to TRUE no modal is shown when a component is dragged onto the form.
* @property {boolean} [noDefaultSubmitButton] - Set to TRUE to not include the default submit button in Webforms.
* @property {boolean} [alwaysConfirmComponentRemoval] - Set to TRUE to always require confirmation before removing a component.
* @property {object} [formConfig] - Form configurations to apply to forms being created. These configurations are added to the "config" property of the form object.
* @property {string} [resourceTag] - The tag to use to query for the "Existing Resource Fields" section of the builder.
* @property {import('./Form').FormOptions} [editForm] - The options to apply to the Edit Form (the form that shows inside the modal when you edit a component).
* @property {string} [language] - The language to load into the form builder.
* @property {object} [builder] - The builder options to pass to the builder.
* @property {'form'|'wizard'|'pdf'} [display] - The display mode of the builder.
* @property {string} [resourceFilter] - Filter applied to the resources that appear in the builder's Existing Resource Fields.
* @property {boolean} [noSource] - When set to TRUE, the resource ID in the builder's Existing Resource Fields will not be linked.
* @property {boolean} [showFullJsonSchema] - When set to TRUE, the full JSON schema will be displayed in the JSON edit menu.
*/
/** @type {FormBuilderOptions} */
static options = {};
/** @type {FormBuilderOptions} */
options;
/**
* Creates a new form builder.
* @param {HTMLElement} element - The HTML element to place the form builder.
* @param {string | object} form - The form to pass to the builder
* @param {FormBuilderOptions} options - The options to create this builder.
* @returns {FormBuilder} - The form builder instance.
*/
constructor(element, form, options) {
form = form || {};
options = options || {};
super(element, form, Object.assign(
options,
FormBuilder.options,
((Formio.options && Formio.options.builder) ? Formio.options.builder : {})
));
}
create(display) {
if (Builders.builders[display]) {
return new Builders.builders[display](this.element, this.options);
}
else {
// eslint-disable-next-line new-cap
return new Builders.builders['webform'](this.element, this.options);
}
}
}
/**
* Factory that creates a new form builder based on the form parameter.
* @param {HTMLElement} element - The HTML Element to add this form to.
* @param {string|object} form - The src of the form, or a form object.
* @param {object} options - The options to create this form.
* @returns {Promise} - When the form is instance is ready.
*/
Formio.builder = (element, form, options) => {
return (new FormBuilder(element, form, options)).ready;
};
Formio.FormBuilder = FormBuilder;