From 2fe896c1e9d2562c9839f385dd797aa925b9272d Mon Sep 17 00:00:00 2001 From: ZenMasterJacob20011 Date: Tue, 9 Jul 2024 10:57:49 -0500 Subject: [PATCH] added dragula to this.root --- src/Webform.js | 3 ++ src/components/datagrid/DataGrid.unit.js | 8 +++++ src/components/datagrid/fixtures/comp9.js | 42 +++++++++++++++++++++++ src/components/datagrid/fixtures/index.js | 3 +- 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 src/components/datagrid/fixtures/comp9.js diff --git a/src/Webform.js b/src/Webform.js index 6ac03b7d55..e6b5b412f6 100644 --- a/src/Webform.js +++ b/src/Webform.js @@ -15,6 +15,7 @@ import { getArrayFromComponentPath, } from "./utils/utils"; import { eachComponent } from "./utils/formUtils"; +import dragula from "dragula"; // Initialize the available forms. Formio.forms = {}; @@ -322,6 +323,8 @@ export default class Webform extends NestedDataComponent { // Ensure the root is set to this component. this.root = this; this.localRoot = this; + + this.root.dragulaLib = dragula; } /* eslint-enable max-statements */ diff --git a/src/components/datagrid/DataGrid.unit.js b/src/components/datagrid/DataGrid.unit.js index 77f873617b..31a994f4af 100644 --- a/src/components/datagrid/DataGrid.unit.js +++ b/src/components/datagrid/DataGrid.unit.js @@ -15,6 +15,7 @@ import { comp6, comp7, comp8, + comp9, withDefValue, withRowGroupsAndDefValue, modalWithRequiredFields, @@ -415,6 +416,13 @@ describe('DataGrid Component', () => { assert.equal(component.childComponentsMap['dataGrid[0].radio'].element.querySelector('input').checked, false); }); }); + + it('Should have dragula available when reorder flag is set to true', () => { + return Formio.createForm(document.createElement('div'), comp9, {}).then((form) => { + const dataGridComponent = form.getComponent('dataGrid'); + assert(dataGridComponent.root.dragulaLib, 'could not find dragulaLib'); + }); + }); }); describe('DataGrid Panels', () => { diff --git a/src/components/datagrid/fixtures/comp9.js b/src/components/datagrid/fixtures/comp9.js new file mode 100644 index 0000000000..ff4a2f0a44 --- /dev/null +++ b/src/components/datagrid/fixtures/comp9.js @@ -0,0 +1,42 @@ +export default { + "components": [ + { + "label": "Data Grid", + "reorder": true, + "addAnotherPosition": "bottom", + "layoutFixed": false, + "enableRowGroups": false, + "initEmpty": false, + "tableView": false, + "defaultValue": [ + {} + ], + "key": "dataGrid", + "type": "datagrid", + "input": true, + "components": [ + { + "label": "Text Field", + "applyMaskOn": "change", + "tableView": true, + "key": "textField", + "type": "textfield", + "input": true + }, + { + "label": "Number", + "applyMaskOn": "change", + "mask": false, + "tableView": false, + "delimiter": false, + "requireDecimal": false, + "inputFormat": "plain", + "truncateMultipleSpaces": false, + "key": "number", + "type": "number", + "input": true + } + ] + } + ] +} diff --git a/src/components/datagrid/fixtures/index.js b/src/components/datagrid/fixtures/index.js index 74d9f61d00..6c3bb34703 100644 --- a/src/components/datagrid/fixtures/index.js +++ b/src/components/datagrid/fixtures/index.js @@ -6,6 +6,7 @@ import comp5 from './comp5'; import comp6 from './comp6'; import comp7 from './comp7'; import comp8 from './comp8'; +import comp9 from './comp9'; import withDefValue from './comp-with-def-value'; import withRowGroupsAndDefValue from './comp-row-groups-with-def-value'; import modalWithRequiredFields from './comp-modal-with-required-fields'; @@ -15,4 +16,4 @@ import withCollapsibleRowGroups from './comp-with-collapsible-groups'; import withAllowCalculateOverride from './comp-with-allow-calculate-override'; import twoWithAllowCalculatedOverride from './two-comp-with-allow-calculate-override'; import withCheckboxes from './comp-with-checkboxes'; -export { comp1, comp2, comp3, comp4, comp5, comp6, comp7, comp8, withCollapsibleRowGroups, withConditionalFieldsAndValidations, withDefValue, withLogic, withRowGroupsAndDefValue, modalWithRequiredFields, withAllowCalculateOverride, twoWithAllowCalculatedOverride, withCheckboxes }; +export { comp1, comp2, comp3, comp4, comp5, comp6, comp7, comp8, comp9, withCollapsibleRowGroups, withConditionalFieldsAndValidations, withDefValue, withLogic, withRowGroupsAndDefValue, modalWithRequiredFields, withAllowCalculateOverride, twoWithAllowCalculatedOverride, withCheckboxes };