Bartosz Dziewoński has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/352630 )
Change subject: MenuTagMultiselectWidget: Handle the 'selected' config option ...................................................................... MenuTagMultiselectWidget: Handle the 'selected' config option TagMultiselectWidget's 'selected' config option handling didn't work, because this.menu is not yet set up while the parent constructor runs, causing exceptions when #getAllowedValues tried to access it to validate values. Now #getAllowedValues rejects everything when this.menu is not set up yet. To handle the 'selected' config option being passed, simply try to set the value again after our setup completes. Also add examples to demos. Bug: T164750 Change-Id: I0a62a947f1229bc957de9a79c451f309c4269d3c --- M demos/pages/widgets.js M src/widgets/MenuTagMultiselectWidget.js 2 files changed, 36 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/oojs/ui refs/changes/30/352630/1 diff --git a/demos/pages/widgets.js b/demos/pages/widgets.js index 15d3839..72cf616 100644 --- a/demos/pages/widgets.js +++ b/demos/pages/widgets.js @@ -1446,6 +1446,33 @@ ), new OO.ui.FieldLayout( new OO.ui.MenuTagMultiselectWidget( { + selected: [ + { data: 'foo', label: 'Label for foo' }, + { data: 'bar', label: 'Label for bar' } + ], + options: [ + { data: 'foo', label: 'Label for foo' }, + { data: 'bar', label: 'Label for bar' }, + { data: 'baz', label: 'Label for baz' } + ] + } ), + { + label: 'MenuTagMultiselectWidget (initially selected, preset options)', + align: 'top' + } + ), + new OO.ui.FieldLayout( + new OO.ui.MenuTagMultiselectWidget( { + selected: [ 'foo', 'bar' ], + allowArbitrary: true + } ), + { + label: 'MenuTagMultiselectWidget (initially selected, allowArbitrary)', + align: 'top' + } + ), + new OO.ui.FieldLayout( + new OO.ui.MenuTagMultiselectWidget( { allowArbitrary: false, options: [ { data: 'abc', label: 'Label for abc' }, diff --git a/src/widgets/MenuTagMultiselectWidget.js b/src/widgets/MenuTagMultiselectWidget.js index ee35b22..5affde6 100644 --- a/src/widgets/MenuTagMultiselectWidget.js +++ b/src/widgets/MenuTagMultiselectWidget.js @@ -66,6 +66,11 @@ .append( this.menu.$element ); this.$element .addClass( 'oo-ui-menuTagMultiselectWidget' ); + // TagMultiselectWidget already does this, but it doesn't work right because this.menu is not yet + // set up while the parent constructor runs, and #getAllowedValues rejects everything. + if ( config.selected ) { + this.setValue( config.selected ); + } }; /* Initialization */ @@ -234,6 +239,10 @@ * @return {string[]} Allowed data values */ OO.ui.MenuTagMultiselectWidget.prototype.getAllowedValues = function () { + if ( !this.menu ) { + // This is the parent constructor calling us and we're not ready yet, this.menu is not set up. + return this.allowedValues; + } var menuDatas = this.menu.getItems().map( function ( menuItem ) { return menuItem.getData(); } ); -- To view, visit https://gerrit.wikimedia.org/r/352630 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0a62a947f1229bc957de9a79c451f309c4269d3c Gerrit-PatchSet: 1 Gerrit-Project: oojs/ui Gerrit-Branch: master Gerrit-Owner: Bartosz Dziewoński <matma....@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits