mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-28 20:29:15 +02:00
MERGE Using FormField->template in most fields
This commit is contained in:
parent
b36ad3b876
commit
a6148c33da
@ -6,6 +6,10 @@
|
|||||||
*/
|
*/
|
||||||
class CheckboxField extends FormField {
|
class CheckboxField extends FormField {
|
||||||
|
|
||||||
|
protected $template = 'CheckboxField';
|
||||||
|
|
||||||
|
protected $fieldHolderTemplate = 'CheckboxFieldHolder';
|
||||||
|
|
||||||
function setValue($value) {
|
function setValue($value) {
|
||||||
$this->value = ($value) ? 1 : 0;
|
$this->value = ($value) ? 1 : 0;
|
||||||
}
|
}
|
||||||
@ -18,13 +22,6 @@ class CheckboxField extends FormField {
|
|||||||
return ($this->value) ? 1 : 0;
|
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
*/
|
*/
|
||||||
class CheckboxSetField extends OptionsetField {
|
class CheckboxSetField extends OptionsetField {
|
||||||
|
|
||||||
protected $disabled = false;
|
protected $template = 'CheckboxSetField';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Array
|
* @var Array
|
||||||
@ -133,7 +133,7 @@ class CheckboxSetField extends OptionsetField {
|
|||||||
|
|
||||||
$properties = array_merge($properties, array('Options' => new ArrayList($options)));
|
$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) {
|
function setDisabled($val) {
|
||||||
|
@ -16,6 +16,7 @@ class CreditCardField extends TextField {
|
|||||||
"<input autocomplete=\"off\" name=\"{$this->name}[3]\" value=\"$parts[3]\" maxlength=\"4\"" . $this->getTabIndexHTML(3) . " /></span>";
|
"<input autocomplete=\"off\" name=\"{$this->name}[3]\" value=\"$parts[3]\" maxlength=\"4\"" . $this->getTabIndexHTML(3) . " /></span>";
|
||||||
return $field;
|
return $field;
|
||||||
}
|
}
|
||||||
|
|
||||||
function dataValue() {
|
function dataValue() {
|
||||||
if(is_array($this->value)) return implode("", $this->value);
|
if(is_array($this->value)) return implode("", $this->value);
|
||||||
else return $this->value;
|
else return $this->value;
|
||||||
|
@ -103,6 +103,7 @@ class CurrencyField_Readonly extends ReadonlyField{
|
|||||||
$valforInput = $this->value ? Convert::raw2att($val) : "";
|
$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."\" />";
|
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.
|
* This already is a readonly field.
|
||||||
*/
|
*/
|
||||||
|
@ -77,6 +77,8 @@
|
|||||||
*/
|
*/
|
||||||
class DropdownField extends FormField {
|
class DropdownField extends FormField {
|
||||||
|
|
||||||
|
protected $template = 'DropdownField';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var boolean $source Associative or numeric array of all dropdown items,
|
* @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
|
* with array key as the submitted field value, and the array value as a
|
||||||
@ -91,11 +93,6 @@ class DropdownField extends FormField {
|
|||||||
*/
|
*/
|
||||||
protected $isSelected;
|
protected $isSelected;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var boolean $disabled
|
|
||||||
*/
|
|
||||||
protected $disabled;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var boolean $hasEmptyDefault Show the first <option> element as
|
* @var boolean $hasEmptyDefault Show the first <option> element as
|
||||||
* empty (not having a value), with an optional label defined through
|
* empty (not having a value), with an optional label defined through
|
||||||
@ -162,7 +159,7 @@ class DropdownField extends FormField {
|
|||||||
|
|
||||||
$properties = array_merge($properties, array('Options' => new ArrayList($options)));
|
$properties = array_merge($properties, array('Options' => new ArrayList($options)));
|
||||||
|
|
||||||
return $this->customise($properties)->renderWith('DropdownField');
|
return $this->customise($properties)->renderWith($this->getTemplate());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,10 +40,6 @@ if(typeof fromAnOnBlur != 'undefined'){
|
|||||||
JS;
|
JS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Field($properties = array()) {
|
|
||||||
return $this->customise($properties)->renderWith('TextField');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the field type - used by templates.
|
* Returns the field type - used by templates.
|
||||||
* @return string
|
* @return string
|
||||||
|
@ -42,6 +42,8 @@
|
|||||||
*/
|
*/
|
||||||
class FileField extends FormField {
|
class FileField extends FormField {
|
||||||
|
|
||||||
|
protected $template = 'FileField';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restrict filesize for either all filetypes
|
* Restrict filesize for either all filetypes
|
||||||
* or a specific extension, with extension-name
|
* or a specific extension, with extension-name
|
||||||
@ -112,7 +114,7 @@ class FileField extends FormField {
|
|||||||
|
|
||||||
public function Field($properties = array()) {
|
public function Field($properties = array()) {
|
||||||
$properties = array_merge($properties, array('MaxFileSize' => $this->getValidator()->getAllowedMaxFileSize()));
|
$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) {
|
public function saveInto(DataObject $record) {
|
||||||
|
@ -20,6 +20,8 @@
|
|||||||
*/
|
*/
|
||||||
class FormAction extends FormField {
|
class FormAction extends FormField {
|
||||||
|
|
||||||
|
protected $template = 'FormAction';
|
||||||
|
|
||||||
protected $extraData;
|
protected $extraData;
|
||||||
|
|
||||||
protected $action;
|
protected $action;
|
||||||
@ -85,7 +87,7 @@ class FormAction extends FormField {
|
|||||||
'UseButtonTag' => $this->useButtonTag
|
'UseButtonTag' => $this->useButtonTag
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
return $this->customise($properties)->renderWith('FormAction');
|
return $this->customise($properties)->renderWith($this->getTemplate());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Type() {
|
public function Type() {
|
||||||
|
@ -76,7 +76,7 @@ class FormField extends RequestHandler {
|
|||||||
/**
|
/**
|
||||||
* @var String
|
* @var String
|
||||||
*/
|
*/
|
||||||
protected $template;
|
protected $template = 'FormField';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Custom Validation Message for the Field
|
* @var Custom Validation Message for the Field
|
||||||
@ -87,7 +87,7 @@ class FormField extends RequestHandler {
|
|||||||
* Template name to render this FormField field holder into.
|
* Template name to render this FormField field holder into.
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $fieldHolderTemplate;
|
protected $fieldHolderTemplate = 'FieldHolder';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new field.
|
* Create a new field.
|
||||||
@ -334,10 +334,22 @@ class FormField extends RequestHandler {
|
|||||||
return $this->form;
|
return $this->form;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
public function getFieldHolderTemplate() {
|
public function getFieldHolderTemplate() {
|
||||||
return $this->fieldHolderTemplate;
|
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) {
|
public function setFieldHolderTemplate($template) {
|
||||||
$this->fieldHolderTemplate = $template;
|
$this->fieldHolderTemplate = $template;
|
||||||
}
|
}
|
||||||
@ -386,7 +398,9 @@ class FormField extends RequestHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
* @param String
|
||||||
*/
|
*/
|
||||||
@ -412,7 +426,8 @@ class FormField extends RequestHandler {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function Field($properties = array()) {
|
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 @@ class FormField extends RequestHandler {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function FieldHolder($properties = array()) {
|
function FieldHolder($properties = array()) {
|
||||||
return $this->customise($properties)->renderWith(
|
$obj = ($properties) ? $this->customise($properties) : $this;
|
||||||
($this->fieldHolderTemplate) ? $this->fieldHolderTemplate : 'FieldHolder'
|
return $obj->renderWith($this->getFieldHolderTemplate());
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
*/
|
*/
|
||||||
class HeaderField extends DatalessField {
|
class HeaderField extends DatalessField {
|
||||||
|
|
||||||
|
protected $template = 'HeaderField';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int $headingLevel The level of the <h1> to <h6> HTML tag. Default: 2
|
* @var int $headingLevel The level of the <h1> to <h6> HTML tag. Default: 2
|
||||||
*/
|
*/
|
||||||
@ -34,8 +36,4 @@ class HeaderField extends DatalessField {
|
|||||||
return $this->headingLevel;
|
return $this->headingLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
function Field($properties = array()) {
|
|
||||||
return $this->customise($properties)->renderWith('HeaderField');
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -6,9 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
class HiddenField extends FormField {
|
class HiddenField extends FormField {
|
||||||
|
|
||||||
function Field($properties = array()) {
|
protected $template = 'HiddenField';
|
||||||
return $this->customise($properties)->renderWith('HiddenField');
|
|
||||||
}
|
|
||||||
|
|
||||||
function FieldHolder() {
|
function FieldHolder() {
|
||||||
return $this->Field();
|
return $this->Field();
|
||||||
|
@ -21,6 +21,7 @@ class ImageFormAction extends FormAction {
|
|||||||
$this->className = $className;
|
$this->className = $className;
|
||||||
parent::__construct($action, $title, $form);
|
parent::__construct($action, $title, $form);
|
||||||
}
|
}
|
||||||
|
|
||||||
function Field() {
|
function Field() {
|
||||||
Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
|
Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
|
||||||
Requirements::javascript(SAPPHIRE_DIR . '/javascript/ImageFormAction.js');
|
Requirements::javascript(SAPPHIRE_DIR . '/javascript/ImageFormAction.js');
|
||||||
@ -31,5 +32,3 @@ class ImageFormAction extends FormAction {
|
|||||||
return "<input class=\"{$classClause}action\" id=\"" . $this->id() . "\" type=\"image\" name=\"{$this->name}\" src=\"{$this->image}\" title=\"{$this->title}\" alt=\"{$this->title}\" />";
|
return "<input class=\"{$classClause}action\" id=\"" . $this->id() . "\" type=\"image\" name=\"{$this->name}\" src=\"{$this->image}\" title=\"{$this->title}\" alt=\"{$this->title}\" />";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
@ -9,6 +9,8 @@
|
|||||||
*/
|
*/
|
||||||
class LabelField extends DatalessField {
|
class LabelField extends DatalessField {
|
||||||
|
|
||||||
|
protected $template = 'LabelField';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param string $title
|
* @param string $title
|
||||||
@ -27,11 +29,4 @@ class LabelField extends DatalessField {
|
|||||||
parent::__construct($name, $title, $form);
|
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');
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -56,6 +56,8 @@
|
|||||||
*/
|
*/
|
||||||
class OptionsetField extends DropdownField {
|
class OptionsetField extends DropdownField {
|
||||||
|
|
||||||
|
protected $template = 'OptionsetField';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Array
|
* @var Array
|
||||||
*/
|
*/
|
||||||
@ -86,7 +88,7 @@ class OptionsetField extends DropdownField {
|
|||||||
|
|
||||||
$properties = array_merge($properties, array('Options' => new ArrayList($options)));
|
$properties = array_merge($properties, array('Options' => new ArrayList($options)));
|
||||||
|
|
||||||
return $this->customise($properties)->renderWith('OptionsetField');
|
return $this->customise($properties)->renderWith($this->getTemplate());
|
||||||
}
|
}
|
||||||
|
|
||||||
function performReadonlyTransformation() {
|
function performReadonlyTransformation() {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* @package forms
|
* @package forms
|
||||||
* @subpackage fields-formattedinput
|
* @subpackage fields-formattedinput
|
||||||
*/
|
*/
|
||||||
class PasswordField extends FormField {
|
class PasswordField extends TextField {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* maxlength of the password field
|
* maxlength of the password field
|
||||||
@ -24,20 +24,10 @@ class PasswordField extends FormField {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function Field() {
|
function Type() {
|
||||||
$disabled = $this->isDisabled()?"disabled=\"disabled\"":"";
|
return 'password';
|
||||||
$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 />";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes a pretty readonly field with some stars in it
|
* Makes a pretty readonly field with some stars in it
|
||||||
*/
|
*/
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
*/
|
*/
|
||||||
class TextField extends FormField {
|
class TextField extends FormField {
|
||||||
|
|
||||||
|
protected $template = 'TextField';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Int
|
* @var Int
|
||||||
*/
|
*/
|
||||||
@ -43,7 +45,7 @@ class TextField extends FormField {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this->customise($properties)->renderWith('TextField');
|
return parent::Field($properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
function InternallyLabelledField() {
|
function InternallyLabelledField() {
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
*/
|
*/
|
||||||
class TextareaField extends FormField {
|
class TextareaField extends FormField {
|
||||||
|
|
||||||
|
protected $template = 'TextareaField';
|
||||||
|
|
||||||
protected $rows, $cols;
|
protected $rows, $cols;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -57,7 +59,7 @@ class TextareaField extends FormField {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this->customise($properties)->renderWith('TextareaField');
|
return parent::Field($properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user