Page MenuHomePhabricator

HTMLComboboxField does not provide autocomplete in ooui format
Open, Needs TriagePublic

Description

I have following code:

$fields['location'] = [
	'type' => 'combobox',
	'label-message' => 'ainut-app-location',
	'notice-message' => 'ainut-app-location-notice',
	'options' => self::$locations,
	'default' => isset( $defaults['location'] ) ? $defaults['location'] : '',
];

If the form format is ooui, the input acts as an input field with dropdown to select values. This is useless. If the user cannot search, I could as well use regular dropdown (I don't allow values outside from the provided list). In the regular format the suggestions are at least filtered down to match the input, which is good.

Event Timeline

When I used that dropdown, my first reaction was of confusion: am I allowed or not to enter a free form string? What happens if I don't click one of the options from the dropdown?

If the user cannot search, I could as well use regular dropdown (I don't allow values outside from the provided list).

In this case, yes, you should use a regular dropdown.

Just reiterating why I don't prefer to use regular dropdown:

  1. The list is long with couple hundred values, so search would be good
  2. It is currently inconsistent with the non-ooui format.

So it took a lot of debugging, but figured it out:

  • The OOUI widget constructed in php supports the autocomplete, as demonstrated on the demo page[1], so I figured it was an issue with how we were created the object - some configuration option was resulting in the <datalist> element not being included in the output. I tested various different options being removed, but none of them fixed it
  • Eventually, one of the times I reloaded Special:PagesWithProps (which uses the comboxbox, and I was using for testing) the <datalist> *was* there, but then it was removed a second later - I realized that it was being output properly, but then removed by the javascript
  • A bit of testing later, found that infusing (OO.ui.infuse) the element is what resulted in it being removed - and HTMLComboboxField::shouldInfuseOOUI() returns true[2], so the element is automatically infused

Solution for MediaWiki: don't automatically infuse
"Upstream" OOUI bug to report: infusing a ComboBoxInputWidget breaks the autocomplete

[1] https://doc.wikimedia.org/oojs-ui/master/demos/demos.php?page=widgets&theme=wikimediaui&direction=ltr&platform=desktop
[2] https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/core/+/79d37e51cc489a500db8bb2e17525524dcb58524/includes/htmlform/fields/HTMLComboboxField.php#62

Change 698356 had a related patch set uploaded (by DannyS712; author: DannyS712):

[mediawiki/core@master] HTMLComboboxField: do not automatically infuse OOUI object

https://gerrit.wikimedia.org/r/698356

I'm sorry that I haven't handled this task. I recently returned from a long bout of unexpected inactivity, and while I plan to resume my contributions here on Phabricator its unfair to claim tasks that I might not work on when others may be interested in handling them. I'm removing myself as the assignee in a batch-action, but if someone feels that I really should be the one to handle this task feel free to re-assign me and I'll take a look.