Skip to content

Commit 978cf9e

Browse files
authored
fixed multiple block sharing same name field (#5012)
1 parent 875a895 commit 978cf9e

File tree

1 file changed

+25
-35
lines changed

1 file changed

+25
-35
lines changed

js/block.js

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3465,26 +3465,21 @@ class Block {
34653465
};
34663466

34673467
if (this.name === "text") {
3468-
// Reuse existing input element or create a new one
3469-
if (!_domCache.textLabelInput) {
3470-
const el = document.createElement("input");
3471-
el.id = "textLabel";
3472-
el.style.position = "absolute";
3473-
el.style.webkitUserSelect = "text";
3474-
el.style.mozUserSelect = "text";
3475-
el.style.msUserSelect = "text";
3476-
el.className = "text";
3477-
el.type = "text";
3478-
_domCache.textLabelInput = el;
3479-
}
3468+
// Create a new input element for this block
3469+
const el = document.createElement("input");
3470+
el.id = "textLabel";
3471+
el.style.position = "absolute";
3472+
el.style.webkitUserSelect = "text";
3473+
el.style.mozUserSelect = "text";
3474+
el.style.msUserSelect = "text";
3475+
el.className = "text";
3476+
el.type = "text";
34803477

34813478
// Ensure it is the child of labelElem
3482-
if (_domCache.textLabelInput.parentNode !== labelElem) {
3483-
labelElem.innerHTML = "";
3484-
labelElem.appendChild(_domCache.textLabelInput);
3485-
}
3479+
labelElem.innerHTML = "";
3480+
labelElem.appendChild(el);
34863481

3487-
this.label = _domCache.textLabelInput;
3482+
this.label = el;
34883483
this.label.value = safetext(labelValue);
34893484
this.label.style.display = "";
34903485
labelElem.classList.add("hasKeyboard");
@@ -4028,27 +4023,22 @@ class Block {
40284023
break;
40294024
}
40304025
} else {
4031-
// Reuse existing input element or create a new one
4032-
if (!_domCache.numberLabelInput) {
4033-
const el = document.createElement("input");
4034-
el.id = "numberLabel";
4035-
el.style.position = "absolute";
4036-
el.style.webkitUserSelect = "text";
4037-
el.style.mozUserSelect = "text";
4038-
el.style.msUserSelect = "text";
4039-
el.className = "number";
4040-
el.type = "number";
4041-
el.step = "any";
4042-
_domCache.numberLabelInput = el;
4043-
}
4026+
// Create a new input element for this block
4027+
const el = document.createElement("input");
4028+
el.id = "numberLabel";
4029+
el.style.position = "absolute";
4030+
el.style.webkitUserSelect = "text";
4031+
el.style.mozUserSelect = "text";
4032+
el.style.msUserSelect = "text";
4033+
el.className = "number";
4034+
el.type = "number";
4035+
el.step = "any";
40444036

40454037
// Ensure it is the child of labelElem
4046-
if (_domCache.numberLabelInput.parentNode !== labelElem) {
4047-
labelElem.innerHTML = "";
4048-
labelElem.appendChild(_domCache.numberLabelInput);
4049-
}
4038+
labelElem.innerHTML = "";
4039+
labelElem.appendChild(el);
40504040

4051-
this.label = _domCache.numberLabelInput;
4041+
this.label = el;
40524042
this.label.value = safetext(labelValue);
40534043
labelElem.classList.add("hasKeyboard");
40544044

0 commit comments

Comments
 (0)