From 54a79cf9f37e26c21b62c0473462ab334d278884 Mon Sep 17 00:00:00 2001 From: Normann Lou Date: Fri, 19 Jun 2009 01:38:34 +0000 Subject: [PATCH] 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 --- forms/ToggleCompositeField.php | 4 +++- javascript/ToggleCompositeField.js | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/forms/ToggleCompositeField.php b/forms/ToggleCompositeField.php index 7f6a92b58..44933b161 100755 --- a/forms/ToggleCompositeField.php +++ b/forms/ToggleCompositeField.php @@ -14,8 +14,10 @@ class ToggleCompositeField extends CompositeField { function __construct($name, $title, $children) { $this->name = $name; $this->title = $title; + $valueField = new HiddenField($name); + $valueField->addExtraClass('hiddenValue'); - $this->startClosed(true); + $children->push($valueField); parent::__construct($children); } diff --git a/javascript/ToggleCompositeField.js b/javascript/ToggleCompositeField.js index a79edf6ed..934a33674 100755 --- a/javascript/ToggleCompositeField.js +++ b/javascript/ToggleCompositeField.js @@ -5,6 +5,7 @@ ToggleCompositeField.prototype = { rules['#' + this.id + ' .trigger'] = { onclick: function(e) { this.toggle(); + this.resetHiddenValue(); Event.stop(e); return false; }.bind(this) }; @@ -21,6 +22,16 @@ ToggleCompositeField.prototype = { Element.toggle($$('#' + this.id + ' .contentMore')[0]); Element.toggle($$('#' + this.id + ' .triggerClosed')[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'); \ No newline at end of file