4 * Radio checkbox fields.
6 class HTMLRadioField
extends HTMLFormField
{
7 function validate( $value, $alldata ) {
8 $p = parent
::validate( $value, $alldata );
14 if ( !is_string( $value ) && !is_int( $value ) ) {
18 $validOptions = HTMLFormField
::flattenOptions( $this->getOptions() );
20 if ( in_array( strval( $value ), $validOptions, true ) ) {
23 return $this->msg( 'htmlform-select-badoption' )->parse();
28 * This returns a block of all the radio options, in one cell.
29 * @see includes/HTMLFormField#getInputHTML()
31 * @param string $value
35 function getInputHTML( $value ) {
36 $html = $this->formatOptions( $this->getOptions(), strval( $value ) );
41 function getInputOOUI( $value ) {
43 foreach ( $this->getOptions() as $label => $data ) {
46 'label' => $this->mOptionsLabelsNotFromMessage ?
new OOUI\
HtmlSnippet( $label ) : $label,
50 return new OOUI\
RadioSelectInputWidget( [
51 'name' => $this->mName
,
54 'options' => $options,
55 'classes' => 'mw-htmlform-flatlist-item',
56 ] + OOUI\Element
::configFromHtmlAttributes(
57 $this->getAttributes( [ 'disabled', 'tabindex' ] )
61 function formatOptions( $options, $value ) {
62 global $wgUseMediaWikiUIEverywhere;
66 $attribs = $this->getAttributes( [ 'disabled', 'tabindex' ] );
67 $elementFunc = [ 'Html', $this->mOptionsLabelsNotFromMessage ?
'rawElement' : 'element' ];
69 # @todo Should this produce an unordered list perhaps?
70 foreach ( $options as $label => $info ) {
71 if ( is_array( $info ) ) {
72 $html .= Html
::rawElement( 'h1', [], $label ) . "\n";
73 $html .= $this->formatOptions( $info, $value );
75 $id = Sanitizer
::escapeId( $this->mID
. "-$info" );
76 $classes = [ 'mw-htmlform-flatlist-item' ];
77 if ( $wgUseMediaWikiUIEverywhere ||
$this->mParent
instanceof VFormHTMLForm
) {
78 $classes[] = 'mw-ui-radio';
80 $radio = Xml
::radio( $this->mName
, $info, $info === $value, $attribs +
[ 'id' => $id ] );
81 $radio .= ' ' . call_user_func( $elementFunc, 'label', [ 'for' => $id ], $label );
83 $html .= ' ' . Html
::rawElement(
85 [ 'class' => $classes ],
94 protected function needsLabel() {