2008-09-29 05:18:23 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* EditableTextField
|
2009-04-17 04:26:40 +02:00
|
|
|
*
|
|
|
|
* This control represents a user-defined text field in a user defined form
|
|
|
|
*
|
|
|
|
* @package userforms
|
2008-09-29 05:18:23 +02:00
|
|
|
*/
|
2009-12-07 03:04:20 +01:00
|
|
|
|
2008-09-29 05:18:23 +02:00
|
|
|
class EditableTextField extends EditableFormField {
|
2009-03-16 22:32:16 +01:00
|
|
|
|
2013-04-03 03:34:43 +02:00
|
|
|
private static $singular_name = 'Text Field';
|
2009-03-16 22:29:19 +01:00
|
|
|
|
2013-04-03 03:34:43 +02:00
|
|
|
private static $plural_name = 'Text Fields';
|
2008-09-29 05:18:23 +02:00
|
|
|
|
2012-05-04 03:39:08 +02:00
|
|
|
public function getFieldConfiguration() {
|
2009-05-11 01:26:22 +02:00
|
|
|
$fields = parent::getFieldConfiguration();
|
2008-09-29 05:18:23 +02:00
|
|
|
|
2012-04-14 08:36:50 +02:00
|
|
|
$min = ($this->getSetting('MinLength')) ? $this->getSetting('MinLength') : '';
|
|
|
|
$max = ($this->getSetting('MaxLength')) ? $this->getSetting('MaxLength') : '';
|
2008-09-29 05:18:23 +02:00
|
|
|
|
2009-04-27 08:00:05 +02:00
|
|
|
$rows = ($this->getSetting('Rows')) ? $this->getSetting('Rows') : '1';
|
|
|
|
|
2012-04-22 21:17:42 +02:00
|
|
|
$extraFields = new FieldList(
|
2008-09-29 05:18:23 +02:00
|
|
|
new FieldGroup(_t('EditableTextField.TEXTLENGTH', 'Text length'),
|
2012-04-14 08:36:50 +02:00
|
|
|
new TextField($this->getSettingName('MinLength'), "", $min),
|
|
|
|
new TextField($this->getSettingName('MaxLength'), " - ", $max)
|
2008-09-29 05:18:23 +02:00
|
|
|
),
|
2012-04-14 08:36:50 +02:00
|
|
|
new TextField($this->getSettingName('Rows'), _t('EditableTextField.NUMBERROWS', 'Number of rows'), $rows)
|
2008-09-29 05:18:23 +02:00
|
|
|
);
|
|
|
|
|
2009-05-11 01:26:22 +02:00
|
|
|
$fields->merge($extraFields);
|
2012-04-14 08:36:50 +02:00
|
|
|
|
2009-05-11 01:26:22 +02:00
|
|
|
return $fields;
|
2008-09-29 05:18:23 +02:00
|
|
|
}
|
|
|
|
|
2010-09-03 07:06:13 +02:00
|
|
|
/**
|
|
|
|
* @return TextareaField|TextField
|
|
|
|
*/
|
2012-05-04 03:39:08 +02:00
|
|
|
public function getFormField() {
|
2009-09-01 04:56:44 +02:00
|
|
|
if($this->getSetting('Rows') && $this->getSetting('Rows') > 1) {
|
2012-07-17 06:09:31 +02:00
|
|
|
$taf = new TextareaField($this->Name, $this->Title);
|
2012-06-08 06:18:36 +02:00
|
|
|
$taf->setRows($this->getSetting('Rows'));
|
|
|
|
return $taf;
|
2009-04-27 08:00:05 +02:00
|
|
|
}
|
|
|
|
else {
|
2009-09-01 04:56:44 +02:00
|
|
|
return new TextField($this->Name, $this->Title, null, $this->getSetting('MaxLength'));
|
2008-09-29 05:18:23 +02:00
|
|
|
}
|
|
|
|
}
|
2009-04-21 05:44:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the validation information related to this field. This is
|
|
|
|
* interrupted as a JSON object for validate plugin and used in the
|
|
|
|
* PHP.
|
|
|
|
*
|
|
|
|
* @see http://docs.jquery.com/Plugins/Validation/Methods
|
2012-04-14 08:36:50 +02:00
|
|
|
* @return array
|
2009-04-21 05:44:13 +02:00
|
|
|
*/
|
|
|
|
public function getValidation() {
|
|
|
|
$options = array();
|
2012-04-14 08:36:50 +02:00
|
|
|
|
|
|
|
if($this->getSetting('MinLength'))
|
|
|
|
$options['minlength'] = $this->getSetting('MinLength');
|
|
|
|
|
|
|
|
if($this->getSetting('MaxLength'))
|
|
|
|
$options['maxlength'] = $this->getSetting('MaxLength');
|
2009-04-21 05:44:13 +02:00
|
|
|
|
|
|
|
return $options;
|
|
|
|
}
|
2012-07-17 06:09:31 +02:00
|
|
|
}
|