20 parent::__construct( $params );
22 if ( isset( $params[
'flatlist'] ) ) {
23 $this->mClass .=
' mw-htmlform-flatlist';
28 $p = parent::validate( $value, $alldata );
34 if ( !is_string( $value ) && !is_int( $value ) ) {
35 return $this->
msg(
'htmlform-required' );
40 if ( in_array( strval( $value ), $validOptions,
true ) ) {
43 return $this->
msg(
'htmlform-select-badoption' );
63 foreach ( $this->
getOptions() as $label => $data ) {
67 'label' => $this->mOptionsLabelsNotFromMessage ?
new OOUI\HtmlSnippet( $label ) : $label,
71 return new OOUI\RadioSelectInputWidget( [
72 'name' => $this->mName,
75 'options' => $options,
76 ] + OOUI\Element::configFromHtmlAttributes(
82 $useMediaWikiUIEverywhere = $this->mParent->getConfig()->get( MainConfigNames::UseMediaWikiUIEverywhere );
86 $attribs = $this->
getAttributes( [
'disabled',
'tabindex' ] );
87 $elementFunc = [ Html::class, $this->mOptionsLabelsNotFromMessage ?
'rawElement' :
'element' ];
89 # @todo Should this produce an unordered list perhaps?
90 foreach ( $options as $label => $info ) {
91 if ( is_array( $info ) ) {
92 $html .= Html::rawElement(
'h1', [], $label ) .
"\n";
95 $id = Sanitizer::escapeIdForAttribute( $this->mID .
"-$info" );
96 $classes = [
'mw-htmlform-flatlist-item' ];
97 if ( $useMediaWikiUIEverywhere || $this->mParent instanceof
VFormHTMLForm ) {
98 $classes[] =
'mw-ui-radio';
100 $radio = Xml::radio( $this->mName, $info, $info === $value, $attribs + [
'id' => $id ] );
101 $radio .=
"\u{00A0}" . call_user_func( $elementFunc,
'label', [
'for' => $id ], $label );
103 $html .=
' ' . Html::rawElement(
105 [
'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.