Page MenuHomePhabricator

Allow the OOUI selectandother field to have the required status indicate that either the dropdown or the input box could be used
Open, Needs TriagePublicFeature

Description

Feature summary (what you would like to be able to do and where):
Allow the selectandother field from HTMLForm to allow the "required" attribute be configurable to instead require that either one dropdown option (other than "other") is picked or text is entered into the input. Currently setting required to be true only makes the input required.

Use case(s) (list the steps that you performed to discover that problem, and describe the actual underlying problem which you want to solve. Do not describe only a solution):
On Special:InvestigateBlock and also Special:CheckUser when in 'get users' mode, the block forms allow the user to enter in a required block reason. Being able to add a dropdown reason, like Special:Block has, would improve speed of using the block forms in CheckUser / Investigate, but the field must still be required due to the design requirements so that the block reason would not be empty. In cases like {{CheckUserBlock}} on a IP, linking to the case or user is against policy so there would be multiple occasions that the desired outcome should not have any text in the "other" input field.

Benefits (why should this be implemented?):
This would allow the selectandother field to be used in Special:InvestigateBlock, as the validation seems to be done just on the client side. This would improve Special:CheckUser as a current patch in review relies on a error returned by the server after submitting the form which is not user friendly.

Event Timeline

matmarex subscribed.

("selectorother" field is not a OOUI concept, it only exists in MediaWiki's HTMLForm.)

This seems to already work as you describe – I tested the following on SpecialBlankpage:

	public function execute( $par ) {
		$form = HTMLForm::factory( 'ooui', [
			'foo' => [
				'type' => 'selectorother',
				'required' => true,
				'options' => [
					'foo' => 'foo',
					'bar' => 'bar',
				],
				'label' => 'test',
			]
		], $this->getContext() );
		$form->show();
	}

I've tested again and this does not work as I've described. Attached screenshot for what I mean, which is what is shown just after I pressed the submit button:

image.png (245×1 px, 15 KB)

Also the empty "other" field is marked as having an error by the red outline when a option is selected in the dropdown:

image.png (190×933 px, 11 KB)

In summary I want to be able to not have "Please fill in this field" show unless the "Other" option is selected in the dropdown menu.

The code that was used is shown below:

'reason' => [
	'type' => 'selectandother',
	'options-message' => 'checkuser-block-reason-dropdown',
	'label-message' => 'checkuser-reason',
	'size' => 46,
	'maxlength' => 150,
	'id' => 'blockreason',
	'name' => 'blockreason',
	'cssclass' => 'ext-checkuser-checkuserblock-block-reason',
	'required' => true
],

Implementation wise this may need a bit of JS as I don't think there would be a HTML method to do this.

Youre using "selectandother" in this example :) (They could be better named. Maybe we should add aliases with dashes or something.)

Ah. I had not realised there was a difference, and so probably when looking for the name of it in the HTMLForm.php source code looked at the first defined in source ignoring the one I had used directly below. I think my use case would still need the "selectandother" version as it should also be possible to use both, so I think this ticket still is okay (after a rename and task description update). Thanks for noticing that and testing it.

Dreamy_Jazz renamed this task from Allow the OOUI selectorother field to have the required status indicate that either the dropdown or the input box could be used to Allow the OOUI selectandother field to have the required status indicate that either the dropdown or the input box could be used.Oct 9 2022, 7:33 PM
Dreamy_Jazz updated the task description. (Show Details)