$attr = array(
'class' => 'mw-htmlform-submit ' . $this->mClass,
'id' => $this->mID,
- );
-
- if ( !empty( $this->mParams['disabled'] ) ) {
- $attr['disabled'] = 'disabled';
- }
+ ) + $this->getAttributes( array( 'disabled', 'tabindex' ) );
return Html::input( $this->mName, $value, $this->buttonType, $attr );
}
$attr = $this->getTooltipAndAccessKey();
$attr['id'] = $this->mID;
- if ( !empty( $this->mParams['disabled'] ) ) {
- $attr['disabled'] = 'disabled';
- }
+ $attr += $this->getAttributes( array( 'disabled', 'tabindex' ) );
if ( $this->mClass !== '' ) {
$attr['class'] = $this->mClass;
function getInputHTML( $value ) {
$html = '';
$tableContents = '';
- $attribs = array();
$rows = $this->mParams['rows'];
$columns = $this->mParams['columns'];
- // If the disabled param is set, disable all the options
- if ( !empty( $this->mParams['disabled'] ) ) {
- $attribs['disabled'] = 'disabled';
- }
+ $attribs = $this->getAttributes( array( 'disabled', 'tabindex' ) );
// Build the column headers
$headerContents = Html::rawElement( 'td', array(), ' ' );
return Linker::tooltipAndAccesskeyAttribs( $this->mParams['tooltip'] );
}
+ /**
+ * Returns the given attributes from the parameters
+ *
+ * @param array $list List of attributes to get
+ * @return array Attributes
+ */
+ public function getAttributes( array $list ) {
+ static $boolAttribs = array( 'disabled', 'required', 'autofocus', 'multiple', 'readonly' );
+
+ $ret = array();
+
+ foreach( $list as $key ) {
+ if ( in_array( $key, $boolAttribs ) ) {
+ if ( !empty( $this->mParams[$key] ) ) {
+ $ret[$key] = '';
+ }
+ } elseif ( isset( $this->mParams[$key] ) ) {
+ $ret[$key] = $this->mParams[$key];
+ }
+ }
+
+ return $ret;
+ }
+
/**
* flatten an array of options to a single array, for instance,
* a set of "<options>" inside "<optgroups>".
function formatOptions( $options, $value ) {
$html = '';
- $attribs = array();
-
- if ( !empty( $this->mParams['disabled'] ) ) {
- $attribs['disabled'] = 'disabled';
- }
+ $attribs = $this->getAttributes( array( 'disabled', 'tabindex' ) );
foreach ( $options as $label => $info ) {
if ( is_array( $info ) ) {
function formatOptions( $options, $value ) {
$html = '';
- $attribs = array();
- if ( !empty( $this->mParams['disabled'] ) ) {
- $attribs['disabled'] = 'disabled';
- }
+ $attribs = $this->getAttributes( array( 'disabled', 'tabindex' ) );
# @todo Should this produce an unordered list perhaps?
foreach ( $options as $label => $info ) {
$textAttribs['class'] = $this->mClass;
}
- foreach ( array( 'required', 'autofocus', 'multiple', 'disabled' ) as $param ) {
- if ( isset( $this->mParams[$param] ) ) {
- $textAttribs[$param] = '';
- }
- }
+ $allowedParams = array(
+ 'required',
+ 'autofocus',
+ 'multiple',
+ 'disabled',
+ 'tabindex'
+ );
+
+ $textAttribs += $this->getAttributes( $allowedParams );
$textbox = Html::input( $this->mName . '-other', $value[2], 'text', $textAttribs );
$select->setAttribute( 'disabled', 'disabled' );
}
+ if ( isset( $this->mParams['tabindex'] ) ) {
+ $select->setAttribute( 'tabindex', $this->mParams['tabindex'] );
+ }
+
if ( $this->mClass !== '' ) {
$select->setAttribute( 'class', $this->mClass );
}
$tbAttribs['disabled'] = 'disabled';
}
+ if ( isset( $this->mParams['tabindex'] ) ) {
+ $select->setAttribute( 'tabindex', $this->mParams['tabindex'] );
+ $tbAttribs['tabindex'] = $this->mParams['tabindex'];
+ }
+
$select = $select->getHTML();
if ( isset( $this->mParams['maxlength'] ) ) {
$attribs['class'] = $this->mClass;
}
- if ( !empty( $this->mParams['disabled'] ) ) {
- $attribs['disabled'] = 'disabled';
- }
-
- if ( !empty( $this->mParams['readonly'] ) ) {
- $attribs['readonly'] = 'readonly';
- }
-
- if ( isset( $this->mParams['placeholder'] ) ) {
- $attribs['placeholder'] = $this->mParams['placeholder'];
- }
-
- foreach ( array( 'required', 'autofocus' ) as $param ) {
- if ( isset( $this->mParams[$param] ) ) {
- $attribs[$param] = '';
- }
- }
+ $allowedParams = array(
+ 'placeholder',
+ 'tabindex',
+ 'disabled',
+ 'readonly',
+ 'required',
+ 'autofocus'
+ );
+
+ $attribs += $this->getAttributes( $allowedParams );
return Html::element( 'textarea', $attribs, $value );
}
$attribs['class'] = $this->mClass;
}
- if ( !empty( $this->mParams['disabled'] ) ) {
- $attribs['disabled'] = 'disabled';
- }
-
# @todo Enforce pattern, step, required, readonly on the server side as
# well
$allowedParams = array(
'step',
'placeholder',
'list',
- 'maxlength'
+ 'maxlength',
+ 'tabindex',
+ 'disabled',
+ 'required',
+ 'autofocus',
+ 'multiple',
+ 'readonly'
);
- foreach ( $allowedParams as $param ) {
- if ( isset( $this->mParams[$param] ) ) {
- $attribs[$param] = $this->mParams[$param];
- }
- }
- foreach ( array( 'required', 'autofocus', 'multiple', 'readonly' ) as $param ) {
- if ( isset( $this->mParams[$param] ) ) {
- $attribs[$param] = '';
- }
- }
+ $attribs += $this->getAttributes( $allowedParams );
# Implement tiny differences between some field variants
# here, rather than creating a new class for each one which