From 67ff6551117a76e335c28e8e68ec4fb249a3083b Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Fri, 13 Jan 2023 00:39:36 +0000 Subject: [PATCH] Add mechanism for retrieving an existing widget instance from ChooserFactory --- client/src/components/ChooserWidget/index.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/client/src/components/ChooserWidget/index.js b/client/src/components/ChooserWidget/index.js index f5a0bd5092..b8fe5aaa81 100644 --- a/client/src/components/ChooserWidget/index.js +++ b/client/src/components/ChooserWidget/index.js @@ -20,6 +20,9 @@ export class Chooser { this.clear(); }); } + + // attach a reference to this widget object onto the root element of the chooser + this.chooserElement.widget = this; } initHTMLElements(id) { @@ -72,6 +75,10 @@ export class Chooser { } } + setStateFromModalData(data) { + this.setState(data); + } + clear() { this.setState(null); } @@ -127,7 +134,7 @@ export class Chooser { ); } this.modal.open(this.getModalOptions(), (result) => { - this.setState(result); + this.setStateFromModalData(result); }); } } @@ -170,4 +177,9 @@ export class ChooserFactory { const options = { ...this.getModalOptions(), ...customOptions }; this.modal.open(options, callback); } + + getById(id) { + /* retrieve the widget object corresponding to the given HTML ID */ + return document.getElementById(`${id}-chooser`).widget; + } }