Page MenuHomePhabricator

OOUI: Fields with a help button removes already-added elements
Closed, DeclinedPublicBUG REPORT

Description

On a Wikisource Index page edit form, you can choose to have a "help" icon for a field.

In Gadget JS, if you add something to the field's label

			$( '#wpprpindex-Transclusion' )
				.closest( '.oo-ui-fieldLayout-body' )
				.find( 'label' )
				.append( $( '<a>' ).append( 'Link text' );

It will flash up briefly and then disappear because something is deleting and re-creating the field.

The ProofreadPage extension delivers this JS:

mw.loader.using( 'mediawiki.widgets.CategoryMultiselectWidget' ).done( function () {
	$( function () {
		// eslint-disable-next-line no-jquery/no-global-selector
		$( '.prp-fieldLayout-help' ).each( function () {
			OO.ui.infuse( this );
		} );

I am not sure if that is related.

The added link remains just fine if the help text is not set.

Event Timeline

Inductiveload changed the subtype of this task from "Task" to "Bug Report".Apr 20 2021, 9:27 AM
matmarex subscribed.

This is expected, when a widget is infused, it is essentially recreated from scratch. (See https://www.mediawiki.org/wiki/OOUI/Using_OOUI_in_MediaWiki#Infusion for context.)

To avoid your changes to the DOM being lost when this happens, you should infuse it yourself first, for example:

fieldLayout = OO.ui.infuse( 
	$( '#wpprpindex-Validation_date' )
		.closest( '.oo-ui-fieldLayout' ) 
);

(This will work correctly regardless of whether your code or the extension's code runs first.)

Then you can also use OOUI methods to make changes to the widget:

fieldLayout.setLabel(
	$( '<span>' )
		.text( fieldLayout.getLabel() )
		.append( $( '<a>' ).append( 'Link text' ) )
);

Your changes can still be lost if some other code (e.g. in the ProofreadPage extension) changes the label, though… Possibly you should file a bug with ProofreadPage to add a better way of doing whatever you're doing.