2008-09-29 03:18:23 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* EditableTextField
|
2009-04-17 02:26:40 +00:00
|
|
|
*
|
|
|
|
* This control represents a user-defined text field in a user defined form
|
|
|
|
*
|
|
|
|
* @package userforms
|
2008-09-29 03:18:23 +00:00
|
|
|
*/
|
2009-12-07 02:04:20 +00:00
|
|
|
|
2008-09-29 03:18:23 +00:00
|
|
|
class EditableTextField extends EditableFormField {
|
2009-03-16 21:32:16 +00:00
|
|
|
|
2008-09-29 03:18:23 +00:00
|
|
|
static $singular_name = 'Text field';
|
2009-03-16 21:29:19 +00:00
|
|
|
|
2008-09-29 03:18:23 +00:00
|
|
|
static $plural_name = 'Text fields';
|
|
|
|
|
2009-05-10 23:26:22 +00:00
|
|
|
function getFieldConfiguration() {
|
|
|
|
$fields = parent::getFieldConfiguration();
|
2008-09-29 03:18:23 +00:00
|
|
|
|
|
|
|
// eventually replace hard-coded "Fields"?
|
|
|
|
$baseName = "Fields[$this->ID]";
|
|
|
|
|
2009-09-23 03:21:03 +00:00
|
|
|
$minLength = ($this->getSetting('MinLength')) ? $this->getSetting('MinLength') : '';
|
|
|
|
$maxLength = ($this->getSetting('MaxLength')) ? $this->getSetting('MaxLength') : '';
|
2009-04-27 06:00:05 +00:00
|
|
|
$rows = ($this->getSetting('Rows')) ? $this->getSetting('Rows') : '1';
|
|
|
|
|
2008-09-29 03:18:23 +00:00
|
|
|
$extraFields = new FieldSet(
|
|
|
|
new FieldGroup(_t('EditableTextField.TEXTLENGTH', 'Text length'),
|
2009-04-27 06:00:05 +00:00
|
|
|
new TextField($baseName . "[CustomSettings][MinLength]", "", $minLength),
|
|
|
|
new TextField($baseName . "[CustomSettings][MaxLength]", " - ", $maxLength)
|
2008-09-29 03:18:23 +00:00
|
|
|
),
|
2009-04-27 06:00:05 +00:00
|
|
|
new TextField($baseName . "[CustomSettings][Rows]", _t('EditableTextField.NUMBERROWS', 'Number of rows'), $rows)
|
2008-09-29 03:18:23 +00:00
|
|
|
);
|
|
|
|
|
2009-05-10 23:26:22 +00:00
|
|
|
$fields->merge($extraFields);
|
|
|
|
return $fields;
|
2008-09-29 03:18:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getFormField() {
|
2009-09-01 02:56:44 +00:00
|
|
|
if($this->getSetting('Rows') && $this->getSetting('Rows') > 1) {
|
|
|
|
return new TextareaField($this->Name, $this->Title, $this->getSetting('Rows'));
|
2009-04-27 06:00:05 +00:00
|
|
|
}
|
|
|
|
else {
|
2009-09-01 02:56:44 +00:00
|
|
|
return new TextField($this->Name, $this->Title, null, $this->getSetting('MaxLength'));
|
2008-09-29 03:18:23 +00:00
|
|
|
}
|
|
|
|
}
|
2009-04-21 03:44:13 +00: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
|
|
|
|
* @return Array
|
|
|
|
*/
|
|
|
|
public function getValidation() {
|
|
|
|
$options = array();
|
2009-04-27 06:00:05 +00:00
|
|
|
if($this->getSetting('MinLength')) $options['minlength'] = $this->getSetting('MinLength');
|
|
|
|
if($this->getSetting('MaxLength')) $options['maxlength'] = $this->getSetting('MaxLength');
|
2009-04-21 03:44:13 +00:00
|
|
|
|
|
|
|
return $options;
|
|
|
|
}
|
2009-12-07 02:04:20 +00:00
|
|
|
}
|