0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-25 05:02:57 +01:00

Add mechanism for retrieving an existing widget instance from ChooserFactory

This commit is contained in:
Matt Westcott 2023-01-13 00:39:36 +00:00
parent d534567f81
commit 67ff655111

View File

@ -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;
}
}