3 class HTMLTextField
extends HTMLFormField
{
5 return isset( $this->mParams
['size'] ) ?
$this->mParams
['size'] : 45;
8 function getSpellCheck() {
9 $val = isset( $this->mParams
['spellcheck'] ) ?
$this->mParams
['spellcheck'] : null;
10 if ( is_bool( $val ) ) {
11 // "spellcheck" attribute literally requires "true" or "false" to work.
12 return $val === true ?
'true' : 'false';
17 public function isPersistent() {
18 if ( isset( $this->mParams
['persistent'] ) ) {
19 return $this->mParams
['persistent'];
21 // don't put passwords into the HTML body, they could get cached or otherwise leaked
22 return !( isset( $this->mParams
['type'] ) && $this->mParams
['type'] === 'password' );
25 function getInputHTML( $value ) {
26 if ( !$this->isPersistent() ) {
32 'name' => $this->mName
,
33 'size' => $this->getSize(),
36 'spellcheck' => $this->getSpellCheck(),
37 ] +
$this->getTooltipAndAccessKey() +
$this->getDataAttribs();
39 if ( $this->mClass
!== '' ) {
40 $attribs['class'] = $this->mClass
;
43 # @todo Enforce pattern, step, required, readonly on the server side as
63 $attribs +
= $this->getAttributes( $allowedParams );
66 $type = $this->getType( $attribs );
67 return Html
::input( $this->mName
, $value, $type, $attribs );
70 protected function getType( &$attribs ) {
71 $type = isset( $attribs['type'] ) ?
$attribs['type'] : 'text';
72 unset( $attribs['type'] );
74 # Implement tiny differences between some field variants
75 # here, rather than creating a new class for each one which
76 # is essentially just a clone of this one.
77 if ( isset( $this->mParams
['type'] ) ) {
78 switch ( $this->mParams
['type'] ) {
84 $attribs['step'] = 'any';
91 $type = $this->mParams
['type'];
99 function getInputOOUI( $value ) {
100 if ( !$this->isPersistent() ) {
104 $attribs = $this->getTooltipAndAccessKey();
106 if ( $this->mClass
!== '' ) {
107 $attribs['classes'] = [ $this->mClass
];
110 # @todo Enforce pattern, step, required, readonly on the server side as
126 $attribs +
= OOUI\Element
::configFromHtmlAttributes(
127 $this->getAttributes( $allowedParams )
130 $type = $this->getType( $attribs );
132 return $this->getInputWidget( [
134 'name' => $this->mName
,
140 protected function getInputWidget( $params ) {
141 return new OOUI\
TextInputWidget( $params );
145 * Returns an array of data-* attributes to add to the field.
149 protected function getDataAttribs() {