1 <?php
2 3 4 5 6 7 8
9
10 class EditableTextField extends EditableFormField {
11
12 static $singular_name = 'Text Field';
13
14 static $plural_name = 'Text Fields';
15
16 function getFieldConfiguration() {
17 $fields = parent::getFieldConfiguration();
18
19 $min = ($this->getSetting('MinLength')) ? $this->getSetting('MinLength') : '';
20 $max = ($this->getSetting('MaxLength')) ? $this->getSetting('MaxLength') : '';
21
22 $rows = ($this->getSetting('Rows')) ? $this->getSetting('Rows') : '1';
23
24 $extraFields = new FieldSet(
25 new FieldGroup(_t('EditableTextField.TEXTLENGTH', 'Text length'),
26 new TextField($this->getSettingName('MinLength'), "", $min),
27 new TextField($this->getSettingName('MaxLength'), " - ", $max)
28 ),
29 new TextField($this->getSettingName('Rows'), _t('EditableTextField.NUMBERROWS', 'Number of rows'), $rows)
30 );
31
32 $fields->merge($extraFields);
33
34 return $fields;
35 }
36
37 38 39
40 function getFormField() {
41 if($this->getSetting('Rows') && $this->getSetting('Rows') > 1) {
42 return new TextareaField($this->Name, $this->Title, $this->getSetting('Rows'));
43 }
44 else {
45 return new TextField($this->Name, $this->Title, null, $this->getSetting('MaxLength'));
46 }
47 }
48
49 50 51 52 53 54 55 56
57 public function getValidation() {
58 $options = parent::getValidation();
59
60 if($this->getSetting('MinLength'))
61 $options['minlength'] = $this->getSetting('MinLength');
62
63 if($this->getSetting('MaxLength'))
64 $options['maxlength'] = $this->getSetting('MaxLength');
65
66 return $options;
67 }
68 }
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the
Silverstripe Forums to ask development related questions.
-