<?php
+/**
+ * <input> field.
+ *
+ * Besides the parameters recognized by HTMLFormField, the following are
+ * recognized:
+ * autocomplete - HTML autocomplete value (a boolean for on/off or a string according to
+ * https://html.spec.whatwg.org/multipage/forms.html#autofill )
+ */
class HTMLTextField extends HTMLFormField {
protected $mPlaceholder = '';
+ /** @var bool HTML autocomplete attribute */
+ protected $autocomplete;
+
/**
* @param array $params
* - type: HTML textfield type
* for password fields)
*/
public function __construct( $params ) {
+ if ( isset( $params['autocomplete'] ) && is_bool( $params['autocomplete'] ) ) {
+ $params['autocomplete'] = $params['autocomplete'] ? 'on' : 'off';
+ }
+
parent::__construct( $params );
if ( isset( $params['placeholder-message'] ) ) {
'required',
'autofocus',
'multiple',
- 'readonly'
+ 'readonly',
+ 'autocomplete',
];
$attribs += $this->getAttributes( $allowedParams );
$value = '';
}
- $attribs = $this->getTooltipAndAccessKey();
+ $attribs = $this->getTooltipAndAccessKeyOOUI();
if ( $this->mClass !== '' ) {
$attribs['classes'] = [ $this->mClass ];
'required',
'tabindex',
'type',
+ 'autocomplete',
];
$attribs += OOUI\Element::configFromHtmlAttributes(
$this->getAttributes( $allowedParams )
);
+ // FIXME T150983 downgrade autocomplete
+ if ( isset( $attribs['autocomplete'] ) ) {
+ if ( $attribs['autocomplete'] === 'on' ) {
+ $attribs['autocomplete'] = true;
+ } elseif ( $attribs['autocomplete'] === 'off' ) {
+ $attribs['autocomplete'] = false;
+ } else {
+ unset( $attribs['autocomplete'] );
+ }
+ }
+
$type = $this->getType( $attribs );
return $this->getInputWidget( [
'name' => $this->mName,
'value' => $value,
'type' => $type,
+ 'dir' => $this->mDir,
] + $attribs );
}