#Repeater
Creates an interface to add and remove a repeatable group of input elements.
###Demo
bower install jquery.repeater --save
npm install jquery.repeater --save
##Templates
Repeater uses the first "data-repeater-item" as a template for added items.
##Rewritten Name Attributes.
Repeater rewrites your name attributes to avoid collisions within the same form.
(since the name attributes will be repeated). In the example below, the
name attributes would be renamed group-a[0][text-input]
and group-a[1][text-input]
.
Checkbox inputs and Multiple Select inputs will have an additional []
appended. So for example a checkbox
with name foo
would be mapped to group-a[0][foo][]
.
Names get reindexed if an item is added or deleted.
##Example
<form class="repeater">
<div data-repeater-list="group-a">
<div data-repeater-item>
<input type="text" name="text-input" value="A"/>
<input data-repeater-delete type="button" value="Delete"/>
</div>
<div data-repeater-item>
<input type="text" name="text-input" value="B"/>
<input data-repeater-delete type="button" value="Delete"/>
</div>
</div>
<input data-repeater-create type="button" value="Add"/>
</form>
<script src="path/to/jquery.js"></script>
<script src="path/to/jquery.repeater/jquery.repeater.js"></script>
<script>
$(document).ready(function () {
$('.repeater').repeater({
defaultValues: {
'text-input': 'foo'
},
show: function () {
$(this).slideDown();
},
hide: function (deleteElement) {
if(confirm('Are you sure you want to delete this element?')) {
$(this).slideUp(deleteElement);
}
},
ready: function (setIndexes) {
$dragAndDrop.on('drop', setIndexes);
},
isFirstItemUndeletable: true
})
});
</script>