Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disallow drop when no associated field is found #1237

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading