Enable max length for textarea field

This commit is contained in:
Saophalkun Ponlu 2017-12-04 16:40:40 +13:00
parent 825ed22214
commit 442f2bb762
3 changed files with 38 additions and 6 deletions

View File

@ -79,6 +79,13 @@ class TextField extends FormField
);
}
public function getSchemaDataDefaults()
{
$data = parent::getSchemaDataDefaults();
$data['data']['maxlength'] = $this->getMaxLength();
return $data;
}
/**
* @return string
*/

View File

@ -28,9 +28,9 @@ class TextareaField extends FormField
'Value' => 'Text',
'ValueEntities' => 'HTMLFragment(array(\'shortcodes\' => false))',
);
protected $schemaDataType = FormField::SCHEMA_DATA_TYPE_TEXT;
/**
* Visible number of text lines.
*
@ -45,19 +45,23 @@ class TextareaField extends FormField
*/
protected $cols = 20;
/**
* @var int
*/
protected $maxLength;
/**
* Set textarea specific schema data
*/
public function getSchemaDataDefaults()
{
$data = parent::getSchemaDataDefaults();
$data['data']['rows'] = $this->getRows();
$data['data']['columns'] = $this->getColumns();
$data['data']['maxlength'] = $this->getMaxLength();
return $data;
}
/**
* Set the number of rows in the textarea
*
@ -106,6 +110,25 @@ class TextareaField extends FormField
return $this->cols;
}
/**
* @param int $maxLength
* @return $this
*/
public function setMaxLength($maxLength)
{
$this->maxLength = $maxLength;
return $this;
}
/**
* @return null|int
*/
public function getMaxLength()
{
return $this->maxLength;
}
/**
* {@inheritdoc}
*/
@ -117,7 +140,8 @@ class TextareaField extends FormField
'rows' => $this->getRows(),
'cols' => $this->getColumns(),
'value' => null,
'type' => null
'type' => null,
'maxlength' => $this->getMaxLength(),
)
);
}

View File

@ -30,6 +30,7 @@
"disabled": false,
"autoFocus": false,
"customValidationMessage": "",
"maxLength": 40,
"validation": {
"required": true,
"max": {