Page MenuHomePhabricator

HTMLRadioField should set the required HTML attribute if required is specified in the form descriptor
Open, Needs TriagePublicBUG REPORT

Description

I am using the HTMLForm API in an extension.

$formDescriptor = [
	'vote' => [
		'type' => 'radio',
		'options' => [
			'yes' => 'yes',
			'no' => 'no',
		],
		'required' => true
	]
];

$htmlForm = new HTMLForm( $formDescriptor );

I would expect the generated HTML to set the required HTML attribute for at least one of the <input type=radio> tags. However that is not the case.
For other input types like text this works as expected, for radio it does not.

Event Timeline

Seems like a good idea. Note that you don't even need to handle the 'required' option at all, HTMLRadioField is already always treated as required (but it's only checked server-side). https://gerrit.wikimedia.org/g/mediawiki/core/+/6dea083839021fb994527c60bf5998b3d159a78f/includes/htmlform/fields/HTMLRadioField.php#35