X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fhtmlform%2Ffields%2FHTMLTextField.php;h=c3da74618bd1d154328792b230dfb52622d603cf;hb=9964ca1a390c446397dcd466916ffed356cdc3c9;hp=3ab71766962ad2be76e30a98f4e8018190a30e36;hpb=81fddcf9e4ff1a66f107260628736788f4601e08;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/htmlform/fields/HTMLTextField.php b/includes/htmlform/fields/HTMLTextField.php index 3ab7176696..c3da74618b 100644 --- a/includes/htmlform/fields/HTMLTextField.php +++ b/includes/htmlform/fields/HTMLTextField.php @@ -1,8 +1,19 @@ 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'] ) ) { @@ -22,11 +37,11 @@ class HTMLTextField extends HTMLFormField { } } - function getSize() { + public function getSize() { return isset( $this->mParams['size'] ) ? $this->mParams['size'] : 45; } - function getSpellCheck() { + public function getSpellCheck() { $val = isset( $this->mParams['spellcheck'] ) ? $this->mParams['spellcheck'] : null; if ( is_bool( $val ) ) { // "spellcheck" attribute literally requires "true" or "false" to work. @@ -43,7 +58,7 @@ class HTMLTextField extends HTMLFormField { return !( isset( $this->mParams['type'] ) && $this->mParams['type'] === 'password' ); } - function getInputHTML( $value ) { + public function getInputHTML( $value ) { if ( !$this->isPersistent() ) { $value = ''; } @@ -80,7 +95,8 @@ class HTMLTextField extends HTMLFormField { 'required', 'autofocus', 'multiple', - 'readonly' + 'readonly', + 'autocomplete', ]; $attribs += $this->getAttributes( $allowedParams ); @@ -119,7 +135,7 @@ class HTMLTextField extends HTMLFormField { return $type; } - function getInputOOUI( $value ) { + public function getInputOOUI( $value ) { if ( !$this->isPersistent() ) { $value = ''; } @@ -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( [