39 if ( isset( $params[
'autocomplete'] ) && is_bool( $params[
'autocomplete'] ) ) {
40 $params[
'autocomplete'] = $params[
'autocomplete'] ?
'on' :
'off';
43 parent::__construct( $params );
45 if ( isset( $params[
'placeholder-message'] ) ) {
46 $this->mPlaceholder = $this->
getMessage( $params[
'placeholder-message'] )->text();
47 } elseif ( isset( $params[
'placeholder'] ) ) {
48 $this->mPlaceholder = $params[
'placeholder'];
57 return $this->mParams[
'size'] ?? 45;
64 $val = $this->mParams[
'spellcheck'] ??
null;
65 if ( is_bool( $val ) ) {
67 return $val ?
'true' :
'false';
76 if ( isset( $this->mParams[
'persistent'] ) ) {
77 return $this->mParams[
'persistent'];
80 return !( isset( $this->mParams[
'type'] ) && $this->mParams[
'type'] ===
'password' );
101 if ( $this->mClass !==
'' ) {
104 if ( $this->mPlaceholder !==
'' ) {
108 # @todo Enforce pattern, step, required, readonly on the server side as
133 $type = $this->
getType( $attribs );
135 $inputHtml = Html::input( $this->mName, $value, $type, $attribs );
144 $type = $attribs[
'type'] ??
'text';
145 unset( $attribs[
'type'] );
147 # Implement tiny differences between some field variants
148 # here, rather than creating a new class for each one which
149 # is essentially just a clone of this one.
150 if ( isset( $this->mParams[
'type'] ) ) {
151 switch ( $this->mParams[
'type'] ) {
154 $attribs[
'step'] = 1;
158 $attribs[
'step'] =
'any';
164 $type = $this->mParams[
'type'];
166 case 'textwithbutton':
167 $type = $this->mParams[
'inputtype'] ??
'text';
186 if ( $this->mClass !==
'' ) {
189 if ( $this->mPlaceholder !==
'' ) {
193 # @todo Enforce pattern, step, required, readonly on the server side as
216 $attribs += \OOUI\Element::configFromHtmlAttributes(
220 $type = $this->
getType( $attribs );
221 if ( isset( $attribs[
'step'] ) && $attribs[
'step'] ===
'any' ) {
222 $attribs[
'step'] =
null;
227 'name' => $this->mName,
230 'dir' => $this->mDir,
249 if ( $this->mPlaceholder !==
'' ) {
275 $extraParams = $this->
getAttributes( [
'start-icon-class',
'end-icon-class' ] );
278 $type = $this->
getType( $attribs );
280 return static::buildCodexComponent( $value, $hasErrors, $type, $this->mName, $attribs, $extraParams );
294 public static function buildCodexComponent( $value, $hasErrors, $type, $name, $inputAttribs, $extraParams = [] ) {
296 $wrapperClass = [
'cdx-text-input' ];
298 $wrapperClass[] =
'cdx-text-input--status-error';
301 $inputAttribs[
'class'][] =
'cdx-text-input__input';
302 $inputHtml = Html::input( $name, $value, $type, $inputAttribs );
306 if ( isset( $extraParams[
'start-icon-class'] ) ) {
308 'cdx-text-input__icon',
309 'cdx-text-input__start-icon',
310 $extraParams[
'start-icon-class'],
312 $wrapperClass[] =
'cdx-text-input--has-start-icon';
314 if ( isset( $extraParams[
'end-icon-class'] ) ) {
316 'cdx-text-input__icon',
317 'cdx-text-input__end-icon',
318 $extraParams[
'end-icon-class'],
320 $wrapperClass[] =
'cdx-text-input--has-end-icon';
323 return Html::rawElement(
325 [
'class' => $wrapperClass ],
326 $inputHtml . $startIconHtml . $endIconHtml
338 return new \OOUI\TextInputWidget( $params );
353class_alias( HTMLTextField::class,
'HTMLTextField' );
getInputHTML( $value)
This function must be implemented to return the HTML to generate the input object itself....
static buildCodexComponent( $value, $hasErrors, $type, $name, $inputAttribs, $extraParams=[])
Build the markup of the Codex component.
getInputCodex( $value, $hasErrors)
Same as getInputHTML, but for Codex.This is called by CodexHTMLForm.If not overridden,...
getDataAttribs()
Returns an array of data-* attributes to add to the field.
getInputOOUI( $value)
Same as getInputHTML, but returns an OOUI object.Defaults to false, which getOOUI will interpret as "...