Skip to content

Commit

Permalink
fix: disallow drop when no formfield is found
Browse files Browse the repository at this point in the history
Closes #1219
  • Loading branch information
Skaiir committed Aug 20, 2024
1 parent ccd9f73 commit 290496a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/form-js-editor/src/features/dragging/Dragging.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ export class Dragging {

if (formFieldNode) {
formField = this._formFieldRegistry.get(formFieldNode.dataset.id);

if (!formField) {
return 'No associated form field in the registry';
}

columns = (formField.layout || {}).columns;

// (1) check for row constraints
Expand Down
51 changes: 51 additions & 0 deletions packages/form-js-editor/test/spec/FormEditor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,57 @@ describe('FormEditor', function () {
});
});

it('should not move form field if it cannot be found in the registry', async function () {
// given
let dragulaCreated = false;

await bootstrapFormEditor({
schema: schemaRows,
container,
bootstrapExecute: (editor) => {
editor.on('dragula.created', () => {
dragulaCreated = true;
});
},
});

const formFieldRegistry = formEditor.get('formFieldRegistry');

expect(dragulaCreated).to.be.true;

const formField = formFieldRegistry.get('Textfield_1');

// assume
expectLayout(formField, {
columns: 8,
row: 'Row_1',
});

const formFieldVisualComponnet = container.querySelector('[data-id="Textfield_1"]').parentNode;

const row = container.querySelector('[data-row-id=Row_4]');
const bounds = row.getBoundingClientRect();

formFieldRegistry._formFields['Textfield_1'] = undefined;

// when
startDragging(container, formFieldVisualComponnet);
moveDragging(container, {
clientX: bounds.x + 10,
clientY: bounds.y + 10,
});

endDragging(container);

// then
expectLayout(formField, {
columns: 8,
row: 'Row_1',
});

expect(formFieldRegistry.get('Textfield_1')).to.be.undefined;
});

it('should move form field into group', async function () {
// given
let dragulaCreated = false;
Expand Down

0 comments on commit 290496a

Please sign in to comment.