From 942632a509a37bfcb67ed776cac381ad71dda4c7 Mon Sep 17 00:00:00 2001 From: Michael Uzquiano Date: Tue, 6 Aug 2013 00:44:16 -0400 Subject: [PATCH] getValue hands back undefined if !required and no children --- js/fields/advanced/MapField.js | 9 ++++++++- js/fields/basic/ArrayField.js | 17 +++++++++++++++-- js/fields/basic/ObjectField.js | 16 +++++++++++++--- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/js/fields/advanced/MapField.js b/js/fields/advanced/MapField.js index 718b9539b..6c333a7db 100644 --- a/js/fields/advanced/MapField.js +++ b/js/fields/advanced/MapField.js @@ -57,7 +57,14 @@ /** * @see Alpaca.ContainerField#getValue */ - getValue: function() { + getValue: function() + { + // if we don't have any children and we're not required, hand back undefined + if (this.children.length === 0 && !this.schema.required) + { + return; + } + var o = {}; for (var i = 0; i < this.children.length; i++) { var v = this.children[i].getValue(); diff --git a/js/fields/basic/ArrayField.js b/js/fields/basic/ArrayField.js index a0361a339..78b460546 100644 --- a/js/fields/basic/ArrayField.js +++ b/js/fields/basic/ArrayField.js @@ -123,10 +123,23 @@ * @see Alpaca.ContainerField#getValue */ getValue: function() { + + // if we're empty and we're also not required, then we hand back undefined + if (this.children.length === 0 && !this.schema.required) + { + return; + } + + // otherwise, construct an array and had it back var o = []; - for (var i = 0; i < this.children.length; i++) { + for (var i = 0; i < this.children.length; i++) + { var v = this.children[i].getValue(); - o.push(v); + + if (typeof(v) !== "undefined") + { + o.push(v); + } } return o; }, diff --git a/js/fields/basic/ObjectField.js b/js/fields/basic/ObjectField.js index 721d8f90d..db0e02699 100644 --- a/js/fields/basic/ObjectField.js +++ b/js/fields/basic/ObjectField.js @@ -100,6 +100,14 @@ * @see Alpaca.Field#getValue */ getValue: function() { + + // if we don't have any children and we're not required, hand back undefined + if (this.children.length === 0 && !this.schema.required) + { + return; + } + + // otherwise, hand back an object with our child properties in it var o = {}; // walk through all of the properties object @@ -114,11 +122,13 @@ var propertyId = this.children[i].propertyId; var fieldValue = this.children[i].getValue(); - if (this.determineAllDependenciesValid(propertyId)) + if (typeof(fieldValue) !== "undefined") { - o[propertyId] = fieldValue; + if (this.determineAllDependenciesValid(propertyId)) + { + o[propertyId] = fieldValue; + } } - } return o;