Skip to content

Commit dc60a92

Browse files
committed
jsdialog: fix problem with getting buttons with unique id
- MakeIdUnique makes id changed by adding suffix - Then we had problem to find the element as we used DOM id - This patch saves original id as additional attribute - When lookup is done we use it first Signed-off-by: Szymon Kłos <[email protected]> Change-Id: Ia97973a8713bff87329fb74e5e4b870b4675a16b
1 parent 11608d1 commit dc60a92

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

browser/src/control/Control.JSDialogBuilder.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,8 +1860,14 @@ window.L.Control.JSDialogBuilder = window.L.Control.extend({
18601860
if (data.command)
18611861
window.L.DomUtil.addClass(div, data.command.replace(':', '').replace('.', ''));
18621862

1863-
if (isRealUnoCommand)
1863+
if (isRealUnoCommand) {
1864+
// there is a problem with JSON crafted manually on the JS side
1865+
// we do not have warranty the id we passed is the one used in the DOM
1866+
// updates might then fail to find such item
1867+
// we need to remember the original ID
1868+
div.setAttribute('modelId', id);
18641869
id = JSDialog.MakeIdUnique(id);
1870+
}
18651871

18661872
div.id = id;
18671873
data.id = id; // change in input data for postprocess
@@ -2392,15 +2398,24 @@ window.L.Control.JSDialogBuilder = window.L.Control.extend({
23922398
builder._explorableMenu(parentContainer, title, data.children, builder, content, data.id);
23932399
},
23942400

2401+
_getItemById: function(container, id) {
2402+
const plainId = this._removeMenuId(id);
2403+
// prefer the modelId first which is unique within single component, DOM id might be changed due to conflict
2404+
let control = container.querySelector('[modelId=\'' + plainId + '\']');
2405+
if (!control)
2406+
control = container.querySelector('[id=\'' + plainId + '\']');
2407+
return control;
2408+
},
2409+
23952410
// executes actions like changing the selection without rebuilding the widget
23962411
executeAction: function(container, data) {
23972412
app.layoutingService.appendLayoutingTask(() => { this.executeActionImpl(container, data); });
23982413
},
23992414

24002415
executeActionImpl: function(container, data) {
2401-
var control = container.querySelector('[id=\'' + this._removeMenuId(data.control_id) + '\']');
2416+
let control = this._getItemById(container, this._removeMenuId(data.control_id));
24022417
if (!control && data.control)
2403-
control = container.querySelector('[id=\'' + this._removeMenuId(data.control.id) + '\']');
2418+
control = this._getItemById(container, this._removeMenuId(data.control.id));
24042419
if (!control) {
24052420
window.app.console.warn('executeAction: not found control with id: "' + data.control_id + '"');
24062421
return;
@@ -2542,8 +2557,8 @@ window.L.Control.JSDialogBuilder = window.L.Control.extend({
25422557
},
25432558

25442559
_updateWidgetImpl: function (container, data, buildFunc) {
2545-
var elementId = this._removeMenuId(data.id);
2546-
var control = container.querySelector('[id=\'' + elementId + '\']');
2560+
const elementId = this._removeMenuId(data.id);
2561+
const control = this._getItemById(container, elementId);
25472562
if (!control) {
25482563
window.app.console.warn('jsdialogupdate: not found control with id: "' + elementId + '"');
25492564
return;

browser/src/control/jsdialog/Component.Toolbar.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,14 @@ class Toolbar extends JSDialogComponent {
126126
this.create();
127127
}
128128

129+
getItemElement(id: string) {
130+
let item = this.parentContainer?.querySelector('[modelId="' + id + '"]');
131+
if (!item) item = this.parentContainer?.querySelector('[id="' + id + '"]');
132+
return item;
133+
}
134+
129135
isItemHidden(id: string): boolean {
130-
const item = this.parentContainer?.querySelector('[id="' + id + '"]');
136+
const item = this.getItemElement(id);
131137
if (!item) return true;
132138
return item.classList.contains('hidden');
133139
}
@@ -149,7 +155,7 @@ class Toolbar extends JSDialogComponent {
149155
}
150156

151157
isItemDisabled(id: string): boolean {
152-
const item = this.parentContainer.querySelector('[id="' + id + '"]');
158+
const item = this.getItemElement(id);
153159
if (!item) return true;
154160
return (
155161
item.hasAttribute('disabled') && item.getAttribute('disabled') !== 'false'

0 commit comments

Comments
 (0)