2013-11-19 12:55:50 +00:00
|
|
|
<?php
|
2013-11-19 13:08:16 +00:00
|
|
|
|
2013-11-19 12:55:50 +00:00
|
|
|
class HTMLTextField extends HTMLFormField {
|
|
|
|
|
function getSize() {
|
2013-11-19 13:08:16 +00:00
|
|
|
return isset( $this->mParams['size'] ) ? $this->mParams['size'] : 45;
|
2013-11-19 12:55:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getInputHTML( $value ) {
|
|
|
|
|
$attribs = array(
|
|
|
|
|
'id' => $this->mID,
|
|
|
|
|
'name' => $this->mName,
|
|
|
|
|
'size' => $this->getSize(),
|
|
|
|
|
'value' => $value,
|
|
|
|
|
) + $this->getTooltipAndAccessKey();
|
|
|
|
|
|
|
|
|
|
if ( $this->mClass !== '' ) {
|
2013-11-19 13:08:16 +00:00
|
|
|
$attribs['class'] = $this->mClass;
|
2013-11-19 12:55:50 +00:00
|
|
|
}
|
|
|
|
|
|
2013-11-19 13:08:16 +00:00
|
|
|
# @todo Enforce pattern, step, required, readonly on the server side as
|
2013-11-19 12:55:50 +00:00
|
|
|
# well
|
|
|
|
|
$allowedParams = array(
|
|
|
|
|
'min',
|
|
|
|
|
'max',
|
|
|
|
|
'pattern',
|
|
|
|
|
'title',
|
|
|
|
|
'step',
|
|
|
|
|
'placeholder',
|
|
|
|
|
'list',
|
2013-05-02 18:27:44 +00:00
|
|
|
'maxlength',
|
|
|
|
|
'tabindex',
|
|
|
|
|
'disabled',
|
|
|
|
|
'required',
|
|
|
|
|
'autofocus',
|
|
|
|
|
'multiple',
|
|
|
|
|
'readonly'
|
2013-11-19 12:55:50 +00:00
|
|
|
);
|
|
|
|
|
|
2013-05-02 18:27:44 +00:00
|
|
|
$attribs += $this->getAttributes( $allowedParams );
|
2013-11-19 12:55:50 +00:00
|
|
|
|
|
|
|
|
# Implement tiny differences between some field variants
|
|
|
|
|
# here, rather than creating a new class for each one which
|
|
|
|
|
# is essentially just a clone of this one.
|
2014-07-30 17:56:25 +00:00
|
|
|
$type = 'text';
|
2013-11-19 13:08:16 +00:00
|
|
|
if ( isset( $this->mParams['type'] ) ) {
|
|
|
|
|
switch ( $this->mParams['type'] ) {
|
2013-11-19 12:55:50 +00:00
|
|
|
case 'int':
|
2014-07-30 17:56:25 +00:00
|
|
|
$type = 'number';
|
2013-11-19 12:55:50 +00:00
|
|
|
break;
|
|
|
|
|
case 'float':
|
2014-07-30 17:56:25 +00:00
|
|
|
$type = 'number';
|
2013-11-19 13:08:16 +00:00
|
|
|
$attribs['step'] = 'any';
|
2013-11-19 12:55:50 +00:00
|
|
|
break;
|
|
|
|
|
# Pass through
|
2014-02-28 21:42:27 +00:00
|
|
|
case 'email':
|
2013-11-19 12:55:50 +00:00
|
|
|
case 'password':
|
|
|
|
|
case 'file':
|
2014-02-28 21:42:27 +00:00
|
|
|
case 'url':
|
2014-07-30 17:56:25 +00:00
|
|
|
$type = $this->mParams['type'];
|
2013-11-19 12:55:50 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-07-30 17:56:25 +00:00
|
|
|
return Html::input( $this->mName, $value, $type, $attribs );
|
2013-11-19 12:55:50 +00:00
|
|
|
}
|
2013-11-19 13:08:16 +00:00
|
|
|
}
|