Merge pull request #7677 from open-sausages/pulls/4/textarea-maxlength

Enable max length for textarea field
This commit is contained in:
Damian Mooyman 2017-12-11 10:34:29 +13:00 committed by GitHub
commit eba6129c07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 58 additions and 12 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,20 +110,46 @@ 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}
*/
public function getAttributes()
{
return array_merge(
$attributes = array_merge(
parent::getAttributes(),
array(
'rows' => $this->getRows(),
'cols' => $this->getColumns(),
'value' => null,
'type' => null
'type' => null,
)
);
$maxLength = $this->getMaxLength();
if ($maxLength) {
$attributes['maxlength'] = $maxLength;
}
return $attributes;
}

View File

@ -31,7 +31,9 @@
"autoFocus": false,
"customValidationMessage": "",
"attributes": [],
"data": [],
"data": {
"maxlength": null
},
"validation": []
},
{

View File

@ -37,7 +37,9 @@
}
},
"attributes": [],
"data": []
"data": {
"maxlength": 40
}
},
{
"name": "Date",
@ -64,7 +66,8 @@
"data": {
"html5": true,
"min": null,
"max": null
"max": null,
"maxlength": null
}
},
{
@ -88,7 +91,9 @@
"numeric": true
},
"attributes": [],
"data": []
"data": {
"maxlength": null
}
},
{
"name": "Money",
@ -111,7 +116,9 @@
"currency": true
},
"attributes": [],
"data": []
"data": {
"maxlength": null
}
},
{
"name": "SecurityID",