Recommend this page to a friend! |
![]() ![]() |
Info | ![]() |
![]() |
![]() |
![]() ![]() |
Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2015-12-17 (10 months ago) ![]() | Not enough user ratings | Total: 164 This week: 1 | All time: 285 This week: 22![]() |
Version | License | JavaScript version | Categories | |||
thrak-repeatable 1.0 | BSD License | 1.0 | HTML, jQuery, Forms |
Description | Author | |||
This is a jQuery plugin that can allow the user to add repeated form inputs. Innovation Award
|
$.repeatable is a jQuery widget that takes a set of html elements and adds plus and minus buttons that allow to duplicate them.
The original idea came from the need to include one or more file attachments in a very simple form that did not require too complicated uploader widgets ; an example is given below :
A simple UI, using plus () and minus () buttons, allows to duplicate the current set of html elements (here, a form field of type<input type="file"/>*) :
And, when you reach the maximum number of repetitions (4, in this precise example), then the UI changes a little bit :
Note how the plus () button became grayed () : You cannot add more files any more because the limit (4) has been reached. However, you can delete any instance you like using the  button.
The code excerpts presented here come from index.html, which contains a small, quick and dirty example, that define a repeatable group of text and file input fields.
Your first task will be to define html content that will be used as a template for duplication.
Here is a div that includes two input fields, one of type text and one of type file, together with their respective labels ; this block of html code will serve as a template for generating instances :
<div id="demo" class="repeatable" min-instances="1" max-instances="4">
<span>Value : </span>
<input type="text" id="value" name="values[]"/>
<span>Attached file : </span>
<input type="file" name="files[]" />
</div>
A few remarks here :
1) You first need jQuery and jQuery UI :
<script language='javascript' src='//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js'></script>
<script language='javascript' src='//ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js'></script>
2) then include the repeatable.js script :
<script language="javascript" type="text/javascript" src="thrak.ui.repeatable-1.0.0.js"></script>
3) And finally include a CSS for styling (one example stylesheet, css/repeatable.css, is provided with this package) :
<link rel="stylesheet" href="css/repeatable.css"/>
This is done by calling the repeatable() function on selected jQuery elements :
<script type="text/javascript">
$(document). ready
(
function ( )
{
$('.repeatable'). repeatable ( ) ;
}
) ;
</script>
The container you defined at step #1 is transformed and looks this way after processing (there will be as many samples of the code below as there are instances) :
<div id="demo" class="repeatable repeatable-instance">
<span>Value : </span>
<input type="text" id="value" name="values[]"/>
<span>Attached file : </span>
<input type="file" name="files[]" />
</div>
<div class="repeatable-buttonset repeatable-buttonset-default repeatable-buttonset-last" target="demo">
<div class="repeatable-button repeatable-button-minus" title="Remove this item"></div>
<div class="repeatable-button repeatable-button-plus" title="Add an item"></div>
</div>
Note the following differences :
The $.repeatable widget then automatically handles user clicks on the plus and minus buttons to add/remove html blocks based on your template.
Initializes a repeatable object on the selected jQuery elements. options is a an object that can have the following members :
A template instance is added the class repeatable-instance, which can be used to further style it (for example, to add a bottom margin to separate consecutive instances).
A button set is appended next to each template instance ; it can have the following classes :
Each button set contains two inner div elements, for the plus and minus buttons. They have the following classes that can be styled :
See css/repeatable.css for an example style sheet. As you might guess, button images are referenced there...
Screenshots | ||
![]() |
File | Role | Description | ||
---|---|---|---|---|
![]() |
||||
![]() |
||||
![]() ![]() |
Example | Example script | ||
![]() ![]() |
Lic. | License file | ||
![]() ![]() |
Data | Disclaimer | ||
![]() ![]() |
Doc. | Help file | ||
![]() ![]() |
Appl. | Widget source |
![]() |
/ | images |
File | Role | Description |
---|---|---|
![]() ![]() |
Data | Button |
![]() ![]() |
Data | Button |
![]() ![]() |
Data | Button |
![]() ![]() |
Data | Button |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
0% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.