Page MenuHomePhabricator

HTMLRadioField should support having NO selected options when the field is infused
Open, Needs TriagePublic

Description

Updated description 2022-03-18

If you have an HTMLRadioField without a default that is referenced by other fields in a hide-if (or disable-if) condition, the first option will be selected automatically by the JS hide-if logic, which is unwanted. More generally, this happens whenever the field is infused (which the hide-if logic does).

Original description

When creating a control with radio buttons, specifying no defaults or null results in the first option being selected.

I don't know if there's a way to do that currently, RadioSelectInputWidget.php:102 makes me think that maybe not.

Event Timeline

Daimona renamed this task from HTMLRadioField should support having NO selected options to HTMLRadioField should support having NO selected options when hide-if is used.Mar 18 2022, 6:15 PM
Daimona claimed this task.
Daimona updated the task description. (Show Details)

This seems to be fixed in the general case, but it's still broken if something uses a hide-if, so I've shamelessly hijacked the task description accordingly.

Daimona renamed this task from HTMLRadioField should support having NO selected options when hide-if is used to HTMLRadioField should support having NO selected options when the field is infused.Mar 18 2022, 6:22 PM
Daimona updated the task description. (Show Details)

So, this is actually OOUI and not MediaWiki-HTMLForm. When the element is infused,the OoUiInputWidget constructor does:

this.setValue( config.value );

which for RadioSelectInputWidget has:

// Only allow setting values that are actually present in the dropdown
selected = this.radioSelectWidget.findItemFromData( value ) ||
	this.radioSelectWidget.findFirstSelectableItem();

I think there are two possible solutions:

  1. In the InputWidget constructor, call setValue iff config.value is set. This seems saner, but I don't know if/how it will impact other field types
  2. In RadioSelectInputWidget.setValue, don't do anything if the given value is not valid. This seems less risky, but again I don't know what impact it could have, plus it seems inconsistent with the dropdown widget

CC @matmarex as author of the patch which introduced the fallback -- what do you think would be the best approach here?