38if ( isset( $params[
'autocomplete'] ) && is_bool( $params[
'autocomplete'] ) ) {
39 $params[
'autocomplete'] = $params[
'autocomplete'] ?
'on' :
'off';
42 parent::__construct( $params );
44if ( isset( $params[
'placeholder-message'] ) ) {
45 $this->mPlaceholder = $this->
getMessage( $params[
'placeholder-message'] )->text();
46 } elseif ( isset( $params[
'placeholder'] ) ) {
47 $this->mPlaceholder = $params[
'placeholder'];
56return $this->mParams[
'size'] ?? 45;
63 $val = $this->mParams[
'spellcheck'] ??
null;
64if ( is_bool( $val ) ) {
65// "spellcheck" attribute literally requires "true" or "false" to work. 66return $val ?
'true' :
'false';
75if ( isset( $this->mParams[
'persistent'] ) ) {
76return $this->mParams[
'persistent'];
78// don't put passwords into the HTML body, they could get cached or otherwise leaked 79return !( isset( $this->mParams[
'type'] ) && $this->mParams[
'type'] ===
'password' );
100if ( $this->mClass !==
'' ) {
103if ( $this->mPlaceholder !==
'' ) {
107 # @todo Enforce pattern, step, required, readonly on the server side as 124// Only used in HTML mode: 132 $type = $this->
getType( $attribs );
134 $inputHtml = Html::input( $this->mName, $value, $type, $attribs );
143 $type = $attribs[
'type'] ??
'text';
144 unset( $attribs[
'type'] );
146 # Implement tiny differences between some field variants 147 # here, rather than creating a new class for each one which 148 # is essentially just a clone of this one. 149if ( isset( $this->mParams[
'type'] ) ) {
150switch ( $this->mParams[
'type'] ) {
153 $attribs[
'step'] = 1;
157 $attribs[
'step'] =
'any';
163 $type = $this->mParams[
'type'];
166 $type = $this->mParams[
'inputtype'] ??
'text';
185if ( $this->mClass !==
'' ) {
188if ( $this->mPlaceholder !==
'' ) {
192 # @todo Enforce pattern, step, required, readonly on the server side as 209// Only used in OOUI mode: 215 $attribs += \OOUI\Element::configFromHtmlAttributes(
219 $type = $this->
getType( $attribs );
220if ( isset( $attribs[
'step'] ) && $attribs[
'step'] ===
'any' ) {
221 $attribs[
'step'] =
null;
226'name' => $this->mName,
248if ( $this->mPlaceholder !==
'' ) {
275 $type = $this->
getType( $attribs );
277return static::buildCodexComponent( $value, $hasErrors, $type, $this->mName, $attribs );
291// Set up classes for the outer <div>. 292 $wrapperClass = [
'cdx-text-input' ];
294 $wrapperClass[] =
'cdx-text-input--status-error';
297 $inputAttribs[
'class'][] =
'cdx-text-input__input';
298 $inputHtml = Html::input( $name, $value, $type, $inputAttribs );
300return Html::rawElement(
'div', [
'class' => $wrapperClass ], $inputHtml );
311return new \OOUI\TextInputWidget( $params );
326class_alias( HTMLTextField::class,
'HTMLTextField' );
getInputHTML( $value)
This function must be implemented to return the HTML to generate the input object itself....
getInputCodex( $value, $hasErrors)
Same as getInputHTML, but for Codex.This is called by CodexHTMLForm.If not overridden,...
bool $autocomplete
HTML autocomplete attribute.
getDataAttribs()
Returns an array of data-* attributes to add to the field.
static buildCodexComponent( $value, $hasErrors, $type, $name, $inputAttribs)
Build the markup of the Codex component.
getInputOOUI( $value)
Same as getInputHTML, but returns an OOUI object.Defaults to false, which getOOUI will interpret as "...
The parent class to generate form fields.
getTooltipAndAccessKey()
Returns the attributes required for the tooltip and accesskey, for Html::element() etc.
getMessage( $value)
Turns a *-message parameter (which could be a MessageSpecifier, or a message name,...
getTooltipAndAccessKeyOOUI()
Returns the attributes required for the tooltip and accesskey, for OOUI widgets' config.
getAttributes(array $list)
Returns the given attributes from the parameters.
This class is a collection of static functions that serve two purposes: