Page MenuHomePhabricator

Lexemes: Grammatical form can render as `[object Object]`
Open, Needs TriagePublic

Description

Steps to reproduce:

  1. Visit a lexeme (eg https://www.wikidata.org/wiki/Lexeme:L123, a sandbox lexeme)
  2. Under Forms, either select add Form, or edit an exist one
  3. In the Grammatical features field, search for and select any element (eg "Sandbox")
  4. Hit the backspace key

Expected result:
Grammatical feature chosen is deleted (same as if the "x" had been clicked)

Actual result:
The visual element for the grammatical feature chosen is replaced with the characters [object Object], which must be removed manually

Event Timeline

I was working on T249167 and T258337 and found what causes this: Never call setLabel() with anything but plain text. When you want a more complex HTML label, do it like this:

new OO.ui.Widget( {
	label: 'Plain text',
	$label: $( '<a>' ).attr( { 'href': '…' } ),
} );

Or like this:

// This is exactly what the LabelElement constructor does
widget.setLabel( 'Plain text' );
widget.setLabelElement( $( '<a>' ).attr( { 'href': '…' } ) );

In both cases the plain text label and the HTML element that wraps the text are passed in separately.

This is a workaround that avoids any of the broken code in setLabel().

Change 618729 had a related patch set uploaded (by Thiemo Kreuz (WMDE); owner: Thiemo Kreuz (WMDE)):
[oojs/ui@master] Fix several broken code paths related to LabelElement#getLabel

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