Skip to content

Commit

Permalink
Merge pull request #38 from massiveart/bugfix/children-index
Browse files Browse the repository at this point in the history
Bugfix/children index
  • Loading branch information
chirimoya committed Apr 6, 2014
2 parents 4ed342d + c691c95 commit 01e3138
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion demo/form/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ <h2>multiple data</h2>
<~ var uid = _.uniqueId('email_'); ~>
<label for="<~= uid ~>">Email
</label>
<input id="<~= uid ~>"
<input id="email<~= index ~>"
type="text"
class="form-element"
name="email"
Expand Down
10 changes: 6 additions & 4 deletions dist/validation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
* This file is part of the Husky Validation.
*
Expand Down Expand Up @@ -757,7 +756,7 @@ define('form/mapper',[
throw 'template has to be defined as <script>';
}

$newChild = {tpl: $child.html(), id: $child.attr('id')};
$newChild = {tpl: $child.html(), id: $child.attr('id'), collection: collection};
element.$children[i] = $newChild;

for (x = -1, len = property.length; ++x < len;) {
Expand All @@ -766,6 +765,7 @@ define('form/mapper',[
}
}
if (!!propertyName) {
$newChild.propertyName = propertyName;
propertyCount = collection.element.getType().getMinOccurs();
this.templates[propertyName] = {tpl: $newChild, collection: collection};
// init default children
Expand Down Expand Up @@ -960,8 +960,9 @@ define('form/mapper',[
},

appendChildren: function($element, $child, tplOptions, data, insertAfter) {
tplOptions = tplOptions || {};
var template = _.template($child.tpl, tplOptions, form.options.delimiter),
var index = $child.collection.element.getType().getChildren($child.id).length,
options = $.extend({}, {index: index}, tplOptions || {}),
template = _.template($child.tpl, options, form.options.delimiter),
$template = $(template),
$newFields = Util.getFields($template),
dfd = $.Deferred(),
Expand Down Expand Up @@ -2500,3 +2501,4 @@ define('validator/regex',[
};

});

Loading

0 comments on commit 01e3138

Please sign in to comment.