21 parent::__construct( $params );
23 if ( isset( $params[
'flatlist'] ) ) {
24 $this->mClass .=
' mw-htmlform-flatlist';
29 $p = parent::validate( $value, $alldata );
35 if ( !is_string( $value ) && !is_int( $value ) ) {
36 return $this->
msg(
'htmlform-required' );
41 if ( in_array( strval( $value ), $validOptions,
true ) ) {
44 return $this->
msg(
'htmlform-select-badoption' );
64 foreach ( $this->
getOptions() as $label => $data ) {
68 'label' => $this->mOptionsLabelsNotFromMessage ?
new OOUI\HtmlSnippet( $label ) : $label,
72 return new OOUI\RadioSelectInputWidget( [
73 'name' => $this->mName,
76 'options' => $options,
77 ] + OOUI\Element::configFromHtmlAttributes(
83 $useMediaWikiUIEverywhere = $this->mParent->getConfig()->get( MainConfigNames::UseMediaWikiUIEverywhere );
87 $attribs = $this->
getAttributes( [
'disabled',
'tabindex' ] );
88 $elementFunc = [ Html::class, $this->mOptionsLabelsNotFromMessage ?
'rawElement' :
'element' ];
90 # @todo Should this produce an unordered list perhaps?
91 foreach ( $options as $label => $info ) {
92 if ( is_array( $info ) ) {
93 $html .= Html::rawElement(
'h1', [], $label ) .
"\n";
96 $id = Sanitizer::escapeIdForAttribute( $this->mID .
"-$info" );
97 $classes = [
'mw-htmlform-flatlist-item' ];
98 if ( $useMediaWikiUIEverywhere || $this->mParent instanceof
VFormHTMLForm ) {
99 $classes[] =
'mw-ui-radio';
101 $radio = Xml::radio( $this->mName, $info, $info === $value, $attribs + [
'id' => $id ] );
102 $radio .=
"\u{00A0}" . call_user_func( $elementFunc,
'label', [
'for' => $id ], $label );
104 $html .=
' ' . Html::rawElement(
106 [
'class' => $classes ],
needsLabel()
Should this field have a label, or is there no input element with the appropriate id for the label to...
validate( $value, $alldata)
Override this function to add specific validation checks on the field input.
formatOptions( $options, $value)
getInputHTML( $value)
This returns a block of all the radio options, in one cell.
getInputOOUI( $value)
Same as getInputHTML, but returns an OOUI object.
A class containing constants representing the names of configuration variables.