Skip to content

Commit 1464e5a

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-70641' into pr-regression-ece
2 parents 595e06d + 8059e0b commit 1464e5a

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

dev/tests/js/jasmine/tests/lib/mage/multiselect.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,5 +133,26 @@ define([
133133
expect(instance.data('mage-multiselect2').appendOptions).toHaveBeenCalled();
134134
expect(instance.data('mage-multiselect2').setCurrentPage).toHaveBeenCalledWith(2);
135135
});
136+
137+
it('multiselect2 item click', function () {
138+
var option = '<div><label><input type="checkbox" value="1"/><span>Label</span></label></div>',
139+
checkbox;
140+
141+
$('body').append(option);
142+
143+
checkbox = $(option).find('input[type="checkbox"]');
144+
checkbox.on('click', instance.data('mage-multiselect2').onCheck);
145+
146+
spyOn(instance.data('mage-multiselect2'), '_createSelectedOption').and.returnValue(true);
147+
148+
checkbox.click();
149+
150+
expect(instance.data('mage-multiselect2')._createSelectedOption).toHaveBeenCalledWith({
151+
value: '1',
152+
label: 'Label'
153+
});
154+
155+
$(option).remove();
156+
});
136157
});
137158
});

lib/web/mage/multiselect.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ define([
135135
var checkbox = event.target,
136136
option = {
137137
value: checkbox.value,
138-
label: $(checkbox.labels[0]).text()
138+
label: $(checkbox).parent('label').text()
139139
};
140140

141141
checkbox.checked ? this._createSelectedOption(option) : this._removeSelectedOption(option);
@@ -275,7 +275,7 @@ define([
275275
* @private
276276
*/
277277
_createSelectedOption: function (option) {
278-
var selectOption = new Option(option.value, option.value, false, true);
278+
var selectOption = new Option(option.label, option.value, false, true);
279279

280280
this.element.append(selectOption);
281281
this.selectedValues.push(option.value);

0 commit comments

Comments
 (0)