Skip to content

Commit 06d6a99

Browse files
committed
Committing v1.0 of plugin
1 parent 251a119 commit 06d6a99

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ The functionality that is provided by this plugin can also be referred to as:
2828
</tr>
2929
</thead>
3030
<tbody class="container">
31-
<script type="text/html" class="template">
32-
<tr class="row">
31+
<tr class="template row">
3332
<td width="10%"><span class="move">Move</span></td>
3433
3534
<td width="10%">An Input Field</td>
@@ -40,7 +39,6 @@ The functionality that is provided by this plugin can also be referred to as:
4039
4140
<td width="10%"><span class="remove">Remove</span></td>
4241
</tr>
43-
</script>
4442
</tbody>
4543
</table>
4644
</div>
@@ -89,9 +87,7 @@ after_remove: null,
8987
<dd>Specifies an element within the row which let's you reposition the current row.</dd>
9088

9189
<dt>template</dt>
92-
<dd>Specifies an element within the container which contains an HTML template for the row. This should be a &lt;script&gt; element. If your template is going to have a nested template
93-
then you must set the type attribute of your script to application/json and you must convert the content to JSON format.
94-
</dd>
90+
<dd>Specifies an element within the container which acts as a row template.</dd>
9591

9692
<dt>before_add</dt>
9793
<dd>Specifies a function to run before a row is added</dd>
@@ -104,4 +100,4 @@ then you must set the type attribute of your script to application/json and you
104100

105101
<dt>after_remove</dt>
106102
<dd>Specifies a function to run after a row is removed</dd>
107-
</dl>
103+
</dl>

repeatable-fields.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* jQuery Repeatable Fields v0.2
2+
* jQuery Repeatable Fields v1.0
33
* http://www.rhyzz.com/repeatable-fields.html
44
*
55
* Copyright (c) 2013 Rhyzz
@@ -26,7 +26,6 @@
2626
var settings = $.extend(default_settings, custom_settings);
2727

2828
// Initialize all repeatable field wrappers
29-
3029
initialize(this);
3130

3231
function initialize(parent) {
@@ -35,14 +34,20 @@
3534

3635
var container = $(wrapper).children(settings.container);
3736

37+
// Disable all form elements inside the row template
38+
$(container).children(settings.template).hide().find(':input').each(function() {
39+
jQuery(this).prop('disabled', true);
40+
});
41+
3842
$(wrapper).on('click', settings.add, function(event) {
3943
event.stopImmediatePropagation();
4044

41-
var row_template = $(container).children(settings.template).html();
45+
var row_template = $($(container).children(settings.template).clone().removeClass(settings.template.replace('.', ''))[0].outerHTML);
4246

43-
if($(container).children(settings.template).attr('type') == 'application/json') {
44-
var row_template = JSON.parse(row_template);
45-
}
47+
// Enable all form elements inside the row template
48+
jQuery(row_template).find(':input').each(function() {
49+
jQuery(this).prop('disabled', false);
50+
});
4651

4752
if(typeof settings.before_add === 'function') {
4853
settings.before_add(container);
@@ -55,7 +60,6 @@
5560
}
5661

5762
// The new row might have it's own repeatable field wrappers so initialize them too
58-
5963
initialize(new_row);
6064
});
6165

@@ -84,14 +88,10 @@
8488
});
8589
}
8690

87-
/*
88-
TODO:
89-
This function doesn't take into consideration multiple references to {{row-count-placeholder}}'s so this might not work with nested
90-
repeatable field wrappers
91-
*/
92-
9391
function after_add(container, new_row) {
94-
var row_count = $(container).children(settings.row).length;
92+
var row_count = $(container).children(settings.row).filter(function() {
93+
return !jQuery(this).hasClass(settings.template.replace('.', ''));
94+
}).length;
9595

9696
$('*', new_row).each(function() {
9797
$.each(this.attributes, function(index, element) {

0 commit comments

Comments
 (0)