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
|
|
|
|
2008-09-29 05:18:23 +02:00
|
|
|
static $singular_name = 'Text field';
|
2009-03-16 22:29:19 +01:00
|
|
|
|
2008-09-29 05:18:23 +02:00
|
|
|
static $plural_name = 'Text fields';
|
|
|
|
|
2009-05-11 01:26:22 +02:00
|
|
|
function getFieldConfiguration() {
|
|
|
|
$fields = parent::getFieldConfiguration();
|
2008-09-29 05:18:23 +02:00
|
|
|
|
|
|
|
// eventually replace hard-coded "Fields"?
|
|
|
|
$baseName = "Fields[$this->ID]";
|
|
|
|
|
2009-09-23 05:21:03 +02:00
|
|
|
$minLength = ($this->getSetting('MinLength')) ? $this->getSetting('MinLength') : '';
|
|
|
|
$maxLength = ($this->getSetting('MaxLength')) ? $this->getSetting('MaxLength') : '';
|
2009-04-27 08:00:05 +02:00
|
|
|
$rows = ($this->getSetting('Rows')) ? $this->getSetting('Rows') : '1';
|
|
|
|
|
2008-09-29 05:18:23 +02:00
|
|
|
$extraFields = new FieldSet(
|
|
|
|
new FieldGroup(_t('EditableTextField.TEXTLENGTH', 'Text length'),
|
2009-04-27 08:00:05 +02:00
|
|
|
new TextField($baseName . "[CustomSettings][MinLength]", "", $minLength),
|
|
|
|
new TextField($baseName . "[CustomSettings][MaxLength]", " - ", $maxLength)
|
2008-09-29 05:18:23 +02:00
|
|
|
),
|
2009-04-27 08:00:05 +02:00
|
|
|
new TextField($baseName . "[CustomSettings][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);
|
|
|
|
return $fields;
|
2008-09-29 05:18:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function getFormField() {
|
2009-09-01 04:56:44 +02:00
|
|
|
if($this->getSetting('Rows') && $this->getSetting('Rows') > 1) {
|
|
|
|
return new TextareaField($this->Name, $this->Title, $this->getSetting('Rows'));
|
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
|
|
|
|
* @return Array
|
|
|
|
*/
|
|
|
|
public function getValidation() {
|
|
|
|
$options = array();
|
2009-04-27 08:00:05 +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;
|
|
|
|
}
|
2009-12-07 03:04:20 +01:00
|
|
|
}
|