Permalink
Browse files

MERGE Using FormField->template in most fields

  • Loading branch information...
1 parent b36ad3b commit a6148c33da3e69be3cf316468ddde3b4047d941d @chillu chillu committed Dec 21, 2011
View
@@ -6,6 +6,10 @@
*/
class CheckboxField extends FormField {
+ protected $template = 'CheckboxField';
+
+ protected $fieldHolderTemplate = 'CheckboxFieldHolder';
+
function setValue($value) {
$this->value = ($value) ? 1 : 0;
}
@@ -18,13 +22,6 @@ function Value() {
return ($this->value) ? 1 : 0;
}
- function Field($properties = array()) {
- return $this->customise($properties)->renderWith('CheckboxField');
- }
-
- function FieldHolder() {
- $this->setFieldHolderTemplate(($this->fieldHolderTemplate) ? $this->fieldHolderTemplate : 'CheckboxFieldHolder');
- return parent::FieldHolder();
}
/**
@@ -33,8 +33,8 @@
* @subpackage fields-basic
*/
class CheckboxSetField extends OptionsetField {
-
- protected $disabled = false;
+
+ protected $template = 'CheckboxSetField';
/**
* @var Array
@@ -133,7 +133,7 @@ function Field($properties = array()) {
$properties = array_merge($properties, array('Options' => new ArrayList($options)));
- return $this->customise($properties)->renderWith('CheckboxSetField');
+ return $this->customise($properties)->renderWith($this->getTemplate());
}
function setDisabled($val) {
@@ -16,6 +16,7 @@ function Field() {
"<input autocomplete=\"off\" name=\"{$this->name}[3]\" value=\"$parts[3]\" maxlength=\"4\"" . $this->getTabIndexHTML(3) . " /></span>";
return $field;
}
+
function dataValue() {
if(is_array($this->value)) return implode("", $this->value);
else return $this->value;
View
@@ -103,6 +103,7 @@ function Field() {
$valforInput = $this->value ? Convert::raw2att($val) : "";
return "<span class=\"readonly ".$this->extraClass()."\" id=\"" . $this->id() . "\">$val</span><input type=\"hidden\" name=\"".$this->name."\" value=\"".$valforInput."\" />";
}
+
/**
* This already is a readonly field.
*/
View
@@ -77,6 +77,8 @@
*/
class DropdownField extends FormField {
+ protected $template = 'DropdownField';
+
/**
* @var boolean $source Associative or numeric array of all dropdown items,
* with array key as the submitted field value, and the array value as a
@@ -92,11 +94,6 @@ class DropdownField extends FormField {
protected $isSelected;
/**
- * @var boolean $disabled
- */
- protected $disabled;
-
- /**
* @var boolean $hasEmptyDefault Show the first <option> element as
* empty (not having a value), with an optional label defined through
* {@link $emptyString}. By default, the <select> element will be
@@ -162,7 +159,7 @@ function Field($properties = array()) {
$properties = array_merge($properties, array('Options' => new ArrayList($options)));
- return $this->customise($properties)->renderWith('DropdownField');
+ return $this->customise($properties)->renderWith($this->getTemplate());
}
/**
View
@@ -5,7 +5,7 @@
* @subpackage fields-formattedinput
*/
class EmailField extends TextField {
-
+
function jsValidation() {
$formID = $this->form->FormName();
$error = _t('EmailField.VALIDATIONJS', 'Please enter an email address.');
@@ -40,10 +40,6 @@ function jsValidation() {
JS;
}
- public function Field($properties = array()) {
- return $this->customise($properties)->renderWith('TextField');
- }
-
/**
* Returns the field type - used by templates.
* @return string
View
@@ -41,6 +41,8 @@
* @subpackage fields-files
*/
class FileField extends FormField {
+
+ protected $template = 'FileField';
/**
* Restrict filesize for either all filetypes
@@ -112,7 +114,7 @@ function __construct($name, $title = null, $value = null, $form = null, $rightTi
public function Field($properties = array()) {
$properties = array_merge($properties, array('MaxFileSize' => $this->getValidator()->getAllowedMaxFileSize()));
- return $this->customise($properties)->renderWith('FileField');
+ return $this->customise($properties)->renderWith($this->getTemplate());
}
public function saveInto(DataObject $record) {
View
@@ -20,6 +20,8 @@
*/
class FormAction extends FormField {
+ protected $template = 'FormAction';
+
protected $extraData;
protected $action;
@@ -85,7 +87,7 @@ function Field($properties = array()) {
'UseButtonTag' => $this->useButtonTag
)
);
- return $this->customise($properties)->renderWith('FormAction');
+ return $this->customise($properties)->renderWith($this->getTemplate());
}
public function Type() {
View
@@ -76,7 +76,7 @@ class FormField extends RequestHandler {
/**
* @var String
*/
- protected $template;
+ protected $template = 'FormField';
/**
* @var Custom Validation Message for the Field
@@ -87,7 +87,7 @@ class FormField extends RequestHandler {
* Template name to render this FormField field holder into.
* @var string
*/
- protected $fieldHolderTemplate;
+ protected $fieldHolderTemplate = 'FieldHolder';
/**
* Create a new field.
@@ -334,10 +334,22 @@ function getForm() {
return $this->form;
}
+ /**
+ * @return String
+ */
public function getFieldHolderTemplate() {
return $this->fieldHolderTemplate;
}
+ /**
+ * Set name of template (without path or extension) for the holder,
+ * which in turn is responsible for rendering {@link Field()}.
+ *
+ * Caution: Not consistently implemented in all subclasses,
+ * please check the {@link Field()} method on the subclass for support.
+ *
+ * @param String
+ */
public function setFieldHolderTemplate($template) {
$this->fieldHolderTemplate = $template;
}
@@ -386,7 +398,9 @@ public function getCustomValidationMessage() {
}
/**
- * Set name of template (without path or extension)
+ * Set name of template (without path or extension).
+ * Caution: Not consistently implemented in all subclasses,
+ * please check the {@link Field()} method on the subclass for support.
*
* @param String
*/
@@ -412,7 +426,8 @@ function getTemplate() {
* @return string
*/
function Field($properties = array()) {
- return $this->customise($properties)->renderWith('FormField');
+ $obj = ($properties) ? $this->customise($properties) : $this;
+ return $obj->renderWith($this->getTemplate());
}
/**
@@ -426,9 +441,8 @@ function Field($properties = array()) {
* @return string
*/
function FieldHolder($properties = array()) {
- return $this->customise($properties)->renderWith(
- ($this->fieldHolderTemplate) ? $this->fieldHolderTemplate : 'FieldHolder'
- );
+ $obj = ($properties) ? $this->customise($properties) : $this;
+ return $obj->renderWith($this->getFieldHolderTemplate());
}
/**
View
@@ -6,6 +6,8 @@
* @subpackage fields-dataless
*/
class HeaderField extends DatalessField {
+
+ protected $template = 'HeaderField';
/**
* @var int $headingLevel The level of the <h1> to <h6> HTML tag. Default: 2
@@ -33,9 +35,5 @@ function __construct($name, $title = null, $headingLevel = 2, $form = null) {
public function getHeadingLevel() {
return $this->headingLevel;
}
-
- function Field($properties = array()) {
- return $this->customise($properties)->renderWith('HeaderField');
- }
}
View
@@ -6,9 +6,7 @@
*/
class HiddenField extends FormField {
- function Field($properties = array()) {
- return $this->customise($properties)->renderWith('HiddenField');
- }
+ protected $template = 'HiddenField';
function FieldHolder() {
return $this->Field();
@@ -21,6 +21,7 @@ function __construct($action, $title = "", $image = "", $hoverImage = null, $cla
$this->className = $className;
parent::__construct($action, $title, $form);
}
+
function Field() {
Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
Requirements::javascript(SAPPHIRE_DIR . '/javascript/ImageFormAction.js');
@@ -30,6 +31,4 @@ function Field() {
if($this->hoverImage) $classClause .= 'rollover ';
return "<input class=\"{$classClause}action\" id=\"" . $this->id() . "\" type=\"image\" name=\"{$this->name}\" src=\"{$this->image}\" title=\"{$this->title}\" alt=\"{$this->title}\" />";
}
-}
-
-?>
+}
View
@@ -8,6 +8,8 @@
* @subpackage fields-dataless
*/
class LabelField extends DatalessField {
+
+ protected $template = 'LabelField';
/**
* @param string $name
@@ -27,11 +29,4 @@ function __construct($name, $title, $form = null) {
parent::__construct($name, $title, $form);
}
- /**
- * Returns a label containing the title, and an HTML class if given.
- */
- function Field($properties = array()) {
- return $this->customise($properties)->renderWith('LabelField');
- }
-
}
View
@@ -55,6 +55,8 @@
* @subpackage fields-basic
*/
class OptionsetField extends DropdownField {
+
+ protected $template = 'OptionsetField';
/**
* @var Array
@@ -86,7 +88,7 @@ function Field($properties = array()) {
$properties = array_merge($properties, array('Options' => new ArrayList($options)));
- return $this->customise($properties)->renderWith('OptionsetField');
+ return $this->customise($properties)->renderWith($this->getTemplate());
}
function performReadonlyTransformation() {
View
@@ -4,7 +4,7 @@
* @package forms
* @subpackage fields-formattedinput
*/
-class PasswordField extends FormField {
+class PasswordField extends TextField {
/**
* maxlength of the password field
@@ -24,20 +24,10 @@ function __construct($name, $title = null, $value = "", $maxLength = null) {
}
- function Field() {
- $disabled = $this->isDisabled()?"disabled=\"disabled\"":"";
- $readonly = $this->isReadonly()?"readonly=\"readonly\"":"";
- if($this->maxLength) {
- return "<input class=\"text\" type=\"password\" id=\"" . $this->id() .
- "\" name=\"{$this->name}\" value=\"" . $this->attrValue() .
- "\" maxlength=\"$this->maxLength\" size=\"$this->maxLength\" $disabled $readonly />";
- } else {
- return "<input class=\"text\" type=\"password\" id=\"" . $this->id() .
- "\" name=\"{$this->name}\" value=\"" . $this->attrValue() . "\" $disabled $readonly />";
- }
+ function Type() {
+ return 'password';
}
-
/**
* Makes a pretty readonly field with some stars in it
*/
View
@@ -6,6 +6,8 @@
*/
class TextField extends FormField {
+ protected $template = 'TextField';
+
/**
* @var Int
*/
@@ -43,7 +45,7 @@ function Field($properties = array()) {
)
);
- return $this->customise($properties)->renderWith('TextField');
+ return parent::Field($properties);
}
function InternallyLabelledField() {
View
@@ -22,6 +22,8 @@
*/
class TextareaField extends FormField {
+ protected $template = 'TextareaField';
+
protected $rows, $cols;
/**
@@ -57,7 +59,7 @@ function Field($properties = array()) {
)
);
- return $this->customise($properties)->renderWith('TextareaField');
+ return parent::Field($properties);
}
/**

0 comments on commit a6148c3

Please sign in to comment.