FEATURE: make a ToggleCompositeField able to save back a boolean value if its name is a boolean field of the related object.

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@79604 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Normann Lou 2009-06-19 01:38:34 +00:00
parent cd59a9b1d7
commit 54a79cf9f3
2 changed files with 14 additions and 1 deletions

View File

@ -14,8 +14,10 @@ class ToggleCompositeField extends CompositeField {
function __construct($name, $title, $children) { function __construct($name, $title, $children) {
$this->name = $name; $this->name = $name;
$this->title = $title; $this->title = $title;
$valueField = new HiddenField($name);
$valueField->addExtraClass('hiddenValue');
$this->startClosed(true); $children->push($valueField);
parent::__construct($children); parent::__construct($children);
} }

View File

@ -5,6 +5,7 @@ ToggleCompositeField.prototype = {
rules['#' + this.id + ' .trigger'] = { rules['#' + this.id + ' .trigger'] = {
onclick: function(e) { onclick: function(e) {
this.toggle(); this.toggle();
this.resetHiddenValue();
Event.stop(e); return false; Event.stop(e); return false;
}.bind(this) }.bind(this)
}; };
@ -21,6 +22,16 @@ ToggleCompositeField.prototype = {
Element.toggle($$('#' + this.id + ' .contentMore')[0]); Element.toggle($$('#' + this.id + ' .contentMore')[0]);
Element.toggle($$('#' + this.id + ' .triggerClosed')[0]); Element.toggle($$('#' + this.id + ' .triggerClosed')[0]);
Element.toggle($$('#' + this.id + ' .triggerOpened')[0]); Element.toggle($$('#' + this.id + ' .triggerOpened')[0]);
},
resetHiddenValue: function() {
var hiddenValue = $$('#' + this.id + ' input.hidden.hiddenValue')[0];
console.log(hiddenValue.value);
if(hiddenValue.value == 1){
hiddenValue.value = 0;
}else if(hiddenValue.value == 0){
hiddenValue.value = 1;
}
} }
} }
ToggleCompositeField.applyTo('div.toggleCompositeField'); ToggleCompositeField.applyTo('div.toggleCompositeField');