Permalink
Browse files

getJSON in array select-multiple with index

  • Loading branch information...
1 parent f0dd38d commit 7cc7833b81cd9691bf513068d9ec46af0ac416c0 AbraaoAlves committed Jan 5, 2012
Showing with 29 additions and 6 deletions.
  1. +13 −2 lib/jsonform.js
  2. +2 −2 runspecs.js
  3. +5 −2 specs/getjson_select_with_multiple.spec.js
  4. +9 −0 specs/templates/multiple.html
View
@@ -188,7 +188,8 @@
for(var property in source) {
if(typeof source[property] === 'object' &&
typeof merged[property] !== "undefined") {
- if($.isArray(merged[property]) && $.isArray(source[property]) && !Object.Equals(merged[property], source[property]))
+
+ if($.isArray(merged[property]) && $.isArray(source[property]) && !Object.Equals(merged[property], source[property].clean()))
merged[property].push(source[property][0]);
else
merge(merged[property], source[property]);
@@ -203,5 +204,15 @@
Object.Equals = Object.Equals || /*bool*/ function(obj1, obj2){
return JSON.stringify(obj1) === JSON.stringify(obj2);
};
-
+
+ Array.prototype.clean = function() {
+
+ for (var i = 0; i < this.length; i++) {
+ if (this[i] === null || this[i] === undefined) {
+ this.splice(i, 1);
+ i--;
+ }
+ }
+ return this;
+ };
})(jQuery);
View
@@ -12,8 +12,8 @@ global.jQuery = require("jquery").create(window);
var jasmine=require('jasmine-node');
//What we're testing
-//require(__dirname + "/lib/jsonform.js")
-require(__dirname + "/minified/jsonform.min.js")
+require(__dirname + "/lib/jsonform.js")
+//require(__dirname + "/minified/jsonform.min.js")
var isVerbose = true;
var showColors = true;
@@ -24,9 +24,12 @@ describe("Get JSON with jsonform when select is multiple", function(){
};
var json = jQuery("form[name='jsonform']").populate(obj).getJSON();
- var codigo = json.partidas[0].conta.codigo;
+
+ var codigo1 = json.partidas[0].conta.codigo;
+ var codigo2 = json.partidas[1].conta.codigo;
- expect(codigo).toEqual([ '1.01.0001', '1.02.0002' ]);
+ expect(codigo1).toEqual([ '1.01.0001', '1.02.0002' ]);
+ expect(codigo2).toEqual([ '1.03.0001', '1.03.0002' ]);
});
});
@@ -8,6 +8,15 @@
</select>
</input>
</p>
+ <p>
+ <label for='partidas[1].conta.codigo'>Débito:</label>
+ <select name='partidas[1].conta.codigo' multiple="multiple">
+ <option value='1.03.0001'>Caixa</option>
+ <option value='1.03.0002'>Banco</option>
+ <option value='1.03.0003'>Compras</option>
+ </select>
+ </input>
+ </p>
<p>
<input type='submit' name='submit'/>
</p>

0 comments on commit 7cc7833

Please sign in to comment.