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 = MediaWikiServices::getInstance()
84 ->getMainConfig()->get( MainConfigNames::UseMediaWikiUIEverywhere );
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 ) ) {
98 $classes = [
'mw-htmlform-flatlist-item' ];
99 if ( $useMediaWikiUIEverywhere || $this->mParent instanceof
VFormHTMLForm ) {
100 $classes[] =
'mw-ui-radio';
102 $radio =
Xml::radio( $this->mName, $info, $info === $value, $attribs + [
'id' => $id ] );
103 $radio .=
"\u{00A0}" . call_user_func( $elementFunc,
'label', [
'for' => $id ], $label );
107 [
'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 rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
A class containing constants representing the names of configuration variables.
static escapeIdForAttribute( $id, $mode=self::ID_PRIMARY)
Given a section name or other user-generated or otherwise unsafe string, escapes it to be a valid HTM...
static radio( $name, $value, $checked=false, $attribs=[])
Convenience function to build an HTML radio button.