Merge "RCFilters: Scroll widget to top when switching view"
[lhc/web/wiklou.git] / includes / htmlform / fields / HTMLTextField.php
index 88f5ec5..1c5a43d 100644 (file)
@@ -1,8 +1,19 @@
 <?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
@@ -13,6 +24,10 @@ class HTMLTextField extends HTMLFormField {
         *     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'] ) ) {
@@ -80,7 +95,8 @@ class HTMLTextField extends HTMLFormField {
                        'required',
                        'autofocus',
                        'multiple',
-                       'readonly'
+                       'readonly',
+                       'autocomplete',
                ];
 
                $attribs += $this->getAttributes( $allowedParams );
@@ -124,7 +140,7 @@ class HTMLTextField extends HTMLFormField {
                        $value = '';
                }
 
-               $attribs = $this->getTooltipAndAccessKey();
+               $attribs = $this->getTooltipAndAccessKeyOOUI();
 
                if ( $this->mClass !== '' ) {
                        $attribs['classes'] = [ $this->mClass ];
@@ -146,12 +162,24 @@ class HTMLTextField extends HTMLFormField {
                        '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( [
@@ -159,6 +187,7 @@ class HTMLTextField extends HTMLFormField {
                        'name' => $this->mName,
                        'value' => $value,
                        'type' => $type,
+                       'dir' => $this->mDir,
                ] + $attribs );
        }