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 ) {
65 if ( is_int( $label ) ) {
66 $label = strval( $label );
71 'label' => $this->mOptionsLabelsNotFromMessage ?
new OOUI\HtmlSnippet( $label ) : $label,
75 return new OOUI\RadioSelectInputWidget( [
76 'name' => $this->mName,
79 'options' => $options,
80 ] + OOUI\Element::configFromHtmlAttributes(
88 $attribs = $this->
getAttributes( [
'disabled',
'tabindex' ] );
89 $elementFunc = [ Html::class, $this->mOptionsLabelsNotFromMessage ?
'rawElement' :
'element' ];
91 # @todo Should this produce an unordered list perhaps?
92 foreach ( $options as $label => $info ) {
93 if ( is_array( $info ) ) {
94 $html .= Html::rawElement(
'h1', [], $label ) .
"\n";
97 $id = Sanitizer::escapeIdForAttribute( $this->mID .
"-$info" );
98 $classes = [
'mw-htmlform-flatlist-item' ];
99 $radio =
Xml::radio( $this->mName, $info, $info === $value, $attribs + [
'id' => $id ] );
100 $radio .=
"\u{00A0}" . call_user_func( $elementFunc,
'label', [
'for' => $id ], $label );
102 $html .=
' ' . Html::rawElement(
104 [
'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.
static radio( $name, $value, $checked=false, $attribs=[])
Convenience function to build an HTML radio button.