form-javascript MDL-24024 Fixed bug with mforms JavaScript whereby dependencies on...
authorSam Hemelryk <sam@moodle.com>
Mon, 13 Sep 2010 08:58:32 +0000 (08:58 +0000)
committerSam Hemelryk <sam@moodle.com>
Mon, 13 Sep 2010 08:58:32 +0000 (08:58 +0000)
lib/form/form.js

index 376b336..c1cb7a6 100644 (file)
@@ -165,9 +165,9 @@ M.form.initFormDependencies = function(Y, formid, dependencies) {
                             hide = false;
                             checkfunction = '_dependency_'+condition;
                             if (Y.Lang.isFunction(this[checkfunction])) {
-                                result = this[checkfunction].apply(this, [this._depElements[dependon], value]);
+                                result = this[checkfunction].apply(this, [this._depElements[dependon], value, e]);
                             } else {
-                                result = this._dependency_default(this._depElements[dependon], value);
+                                result = this._dependency_default(this._depElements[dependon], value, e);
                             }
                             lock = result.lock || false;
                             hide = result.hide || false;
@@ -223,7 +223,10 @@ M.form.initFormDependencies = function(Y, formid, dependencies) {
             _dependency_notchecked : function(elements, value) {
                 var lock = false;
                 elements.each(function(){
-                    lock = lock || !this.get('checked');
+                    if (this.getAttribute('type').toLowerCase()=='radio' && !Y.Node.getDOMNode(this).checked) {
+                        return;
+                    }
+                    lock = lock || !Y.Node.getDOMNode(this).checked;
                 });
                 return {
                     lock : lock,
@@ -233,7 +236,10 @@ M.form.initFormDependencies = function(Y, formid, dependencies) {
             _dependency_checked : function(elements, value) {
                 var lock = false;
                 elements.each(function(){
-                    lock = lock || this.get('checked');
+                    if (this.getAttribute('type').toLowerCase()=='radio' && !Y.Node.getDOMNode(this).checked) {
+                        return;
+                    }
+                    lock = lock || Y.Node.getDOMNode(this).checked;
                 });
                 return {
                     lock : lock,
@@ -253,6 +259,9 @@ M.form.initFormDependencies = function(Y, formid, dependencies) {
             _dependency_eq : function(elements, value) {
                 var lock = false;
                 elements.each(function(){
+                    if (this.getAttribute('type').toLowerCase()=='radio' && !Y.Node.getDOMNode(this).checked) {
+                        return;
+                    }
                     lock = lock || this.get('value') == value;
                 });
                 return {
@@ -266,9 +275,12 @@ M.form.initFormDependencies = function(Y, formid, dependencies) {
                     hide : true
                 }
             },
-            _dependency_default : function(elements, value) {
+            _dependency_default : function(elements, value, ev) {
                 var lock = false;
                 elements.each(function(){
+                    if (this.getAttribute('type').toLowerCase()=='radio' && !Y.Node.getDOMNode(this).checked) {
+                        return;
+                    }
                     lock = lock || this.get('value') != value;
                 });
                 return {