Skip to content

Commit

Permalink
allow collections without objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Niko Berger committed Jul 25, 2013
1 parent 347220d commit c671fd0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
16 changes: 13 additions & 3 deletions sample.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://raw.github.com/corinis/jsForm/master/src/jquery.jsForm.js"></script>
<script src="src/jquery.jsForm.js"></script>
<script>
$(function(){
// some json data
Expand All @@ -10,7 +10,8 @@
description: "long Description\nMultiline", // textarea
links: [{href:'http://www.gargan.org',description:'Gargan.org'},{href:'http://www.github.com',description:'GitHub'}], // lists
active: true, // checkbox
state: "VISIBLE" // selects (enums)
state: "VISIBLE", // selects (enums)
quips: ["Don't left school interfere with your education!", "Can you repeat the question? I was thinking about cookies.", "In my house I'm the boss, my wife is just the decision maker."]
};

// initialize the form, prefix is optional and defaults to data
Expand All @@ -26,7 +27,7 @@
</script>
</head>
<body>
<h1>Simpel Form Test</h1>
<h1>Simple Form Test</h1>
<div id="details">
Name: <input name="data.name"/><br/>
<input type="checkbox" name="data.active"/> active<br/>
Expand All @@ -44,6 +45,15 @@ <h1>Simpel Form Test</h1>
</fieldset>
<button class="add" data-field="data.links">add a link</button><br/>
Additional field: <input name="data.addedField"/>

<fieldset>
<legend>Quips</legend>
<ul class="collection" data-field="data.quips">
<li><input name="quips."/></li>
</ul>
<button class="add" data-field="data.quips">add a quip</button><br/>
</fieldset>

</div>
<button id="show">Show Object</button>
</body>
Expand Down
13 changes: 10 additions & 3 deletions src/jquery.jsForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,8 @@

// skip empty
if(name.length < 1) {
return;
pojo = $(this).val();
return false;
}

var val = $(this).val();
Expand Down Expand Up @@ -631,6 +632,8 @@
// more should not be necessary
}
});

return pojo;
};


Expand Down Expand Up @@ -895,7 +898,7 @@
}

var ele = {};
that._createPojoFromInput($(this), fieldname, ele);
ele = that._createPojoFromInput($(this), fieldname, ele);

// also collect sub-collections
that._getCollection($(this), fieldname, ele, ignoreInvalid);
Expand Down Expand Up @@ -1289,7 +1292,7 @@
/**
* Retrieve a value from a given object by using dot-notation
* @param obj the object to start with
* @param the child to get (dot notation)
* @param the child to get (dot notation)
* @param create set to true and non-existant levels will be created (always returns non-null)
* @private
*/
Expand All @@ -1301,6 +1304,10 @@
if (!obj) {
return "";
}
// reference the object itself
if(expr === "")
return obj;

ret = obj[expr];
if(!ret) {
try {
Expand Down

0 comments on commit c671fd0

Please sign in to comment.