Skip to content

Commit 36c0f5d

Browse files
Merge pull request #315 from adobe-commerce-tier-4/PR-03-12-2024-anna
[Support Tier-4 abukatar] 03-12-2024 Regular delivery of bugfixes and improvements
2 parents d331646 + fdf95e8 commit 36c0f5d

File tree

2 files changed

+93
-14
lines changed
  • app/code/Magento/PageBuilder/view/adminhtml/web/js/form/element
  • dev/tests/js/jasmine/tests/app/code/Magento/PageBuilder/adminhtml/web/js/form/element

2 files changed

+93
-14
lines changed

app/code/Magento/PageBuilder/view/adminhtml/web/js/form/element/html.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,28 @@ define([
5959
name;
6060

6161
this.elements.forEach(function (item) {
62+
if (!$.contains(document.documentElement, item)) {
63+
// item was removed
64+
return;
65+
}
6266
switch (item.type) {
63-
case 'checkbox':
64-
result[item.name] = +!!item.checked;
65-
break;
67+
case 'checkbox':
68+
result[item.name] = +!!item.checked;
69+
break;
6670

67-
case 'radio':
68-
if (item.checked) {
69-
result[item.name] = item.value;
70-
}
71-
break;
71+
case 'radio':
72+
if (item.checked) {
73+
result[item.name] = item.value;
74+
}
75+
break;
7276

73-
case 'select-multiple':
74-
name = item.name.substring(0, item.name.length - 2); //remove [] from the name ending
75-
result[name] = _.pluck(item.selectedOptions, 'value');
76-
break;
77+
case 'select-multiple':
78+
name = item.name.substring(0, item.name.length - 2); //remove [] from the name ending
79+
result[name] = _.pluck(item.selectedOptions, 'value');
80+
break;
7781

78-
default:
79-
result[item.name] = item.value;
82+
default:
83+
result[item.name] = item.value;
8084
}
8185
});
8286

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/************************************************************************
2+
*
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*
6+
* NOTICE: All information contained herein is, and remains
7+
* the property of Adobe and its suppliers, if any. The intellectual
8+
* and technical concepts contained herein are proprietary to Adobe
9+
* and its suppliers and are protected by all applicable intellectual
10+
* property laws, including trade secret and copyright laws.
11+
* Dissemination of this information or reproduction of this material
12+
* is strictly forbidden unless prior written permission is obtained
13+
* from Adobe.
14+
* ************************************************************************
15+
*/
16+
17+
/* eslint-disable max-nested-callbacks */
18+
define([
19+
'Magento_PageBuilder/js/form/element/html',
20+
], function (HtmlUiElement) {
21+
'use strict';
22+
23+
describe('Magento_PageBuilder/js/form/element/html', function () {
24+
var model,
25+
htmlContainer,
26+
formId = 'form-' + Date.now();
27+
28+
function addNewElement(name, value) {
29+
var newElement = document.createElement('li'),
30+
inputElement = document.createElement('input');
31+
32+
inputElement.setAttribute('name', name);
33+
inputElement.setAttribute('type', 'hidden');
34+
inputElement.setAttribute('data-form-part', formId);
35+
inputElement.value = value;
36+
newElement.appendChild(inputElement);
37+
htmlContainer.appendChild(newElement);
38+
model.elements.push(inputElement);
39+
return inputElement;
40+
}
41+
42+
beforeEach(function () {
43+
model = new HtmlUiElement({inputSelector: '[data-form-part=' + formId + ']'});
44+
htmlContainer = document.createElement('ul');
45+
document.body.appendChild(htmlContainer);
46+
});
47+
48+
afterEach(function () {
49+
document.body.removeChild(htmlContainer);
50+
model = null;
51+
htmlContainer = null;
52+
});
53+
54+
describe('"updateValue" method', function () {
55+
it('Should collect all inputs values', function () {
56+
var param1, param2;
57+
58+
model.updateValue();
59+
expect(model.value()).toEqual({});
60+
param1 = addNewElement('param1', 'value1');
61+
model.updateValue();
62+
expect(model.value()).toEqual({param1: 'value1'});
63+
param2 = addNewElement('param2', 'value2');
64+
model.updateValue();
65+
expect(model.value()).toEqual({param1: 'value1', param2: 'value2'});
66+
param2.value = 'value22';
67+
model.updateValue();
68+
expect(model.value()).toEqual({param1: 'value1', param2: 'value22'});
69+
param1.remove();
70+
model.updateValue();
71+
expect(model.value()).toEqual({param2: 'value22'});
72+
});
73+
});
74+
});
75+
});

0 commit comments

Comments
 (0)