mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
parent
cd59a9b1d7
commit
54a79cf9f3
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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');
|
Loading…
Reference in New Issue
Block a user