Page MenuHomePhabricator

How to differentiate between values and labels in ComboBoxInputWidget?
Closed, InvalidPublic


Dear community, I'm requesting advice on an OOUI-related issue with the Page Forms extension and its use of comboboxes with autocompletion over the API. It used to support mapping values to labels, e.g. displaytitles, mapping properties and even mapping templates, but I'm not sure if that functionality has fully survived the switch to OOUI's ComboBoxInputWidget, which happened in 2021.

To be clear, Page Forms has two kinds of autocompletion: local, which is intended for use cases where all of the options can be preloaded, and remote, which relies on an API to retrieve its data and labels for suggestions as the user types. Both are implemented in OOUI, the former through PHP, the latter through JS. It is the remote, JS-based type I'm referring to here.

The ComboBoxInputWidget lets me differentiate between what it calls data and labels if I want to create options for the dropdown list. So far so good, but when the user has selected an option from the list and the value is accepted in the input (good), there is no sign of a label (bad). Confusingly, it's just the value itself, which is what needs to get submitted, that is also displayed to the user.

Many years ago (2017), it was confirmed that this was not yet possible in OOUI (see
mailing list and Stackoverflow). To judge by the code, this is still the default behaviour :

OO.ui.ComboBoxInputWidget.prototype.onMenuChoose = function ( item ) {
	this.setValue( item.getData() );

Even if it is not possible out of the box, it is 2023 and OOUI is meant to be extensible and 'chainable'. I don't know how to go from here, however. Sure I can override onMenuChoose, but how does the ComboBoxInputWidget /TextInputWidget facilitate the 'value-label mechanism'? Are there any best practices I should be aware of, or there creative solutions available?

P.S. TextInputWidget does offer a 'label' property, but it is intended for a rather different purpose.

Event Timeline

Hi @DG. This does not sound like something is wrong in the code base (a so-called "software bug"), but instead like a support request (how to change settings, questions how to do something, etc.).
As Wikimedia Phabricator is for bug reports, enhancement requests, and planning work, please check - Thanks for your understanding!

Well, the first step is to establish whether or not we are, in fact, dealing with a bug or limitation of the software (MediaWiki core). Maybe there is something I'm not understanding, so I didn't want to pre-judge the whole thing. If it is a bug or an inconvenient limitation, and no workaround is available, I would have gone ahead and add a bug report or enhancement request. As for Page Forms, clearly something is broken.

@DG - thinking about it now, I think it would indeed be better to ask this on the "Support desk" or something similar, rather than here - it's true that this might be a bug (actually, that seems likely), but on the other hand, it might not be - and even if it is, the more important thing for now, I would think, is seeing if there's a workaround for it.