Skip to content

Commit

Permalink
getValue hands back undefined if !required and no children
Browse files Browse the repository at this point in the history
  • Loading branch information
uzquiano committed Aug 6, 2013
1 parent fc35174 commit 942632a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
9 changes: 8 additions & 1 deletion js/fields/advanced/MapField.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
17 changes: 15 additions & 2 deletions js/fields/basic/ArrayField.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down
16 changes: 13 additions & 3 deletions js/fields/basic/ObjectField.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit 942632a

Please sign in to comment.