Skip to content

Instantly share code, notes, and snippets.

@Altreus
Created April 19, 2013 10:01
Show Gist options
  • Save Altreus/5419362 to your computer and use it in GitHub Desktop.
Save Altreus/5419362 to your computer and use it in GitHub Desktop.
$.fn.nInputs = function(options) {
var $self = this;
options = $.extend({
number: $self.val(),
container: $self.parent(),
}, options);
var $existing = options.container.find('input');
if ($existing.length < options.number) {
for (var i = $existing.length; i <= options.number; i++) {
// TODO: Sort out attributes here.
options.container.append(options.template.clone(true));
}
}
elseif ($existing.length > options.number) {
$existing.find(':gt(' + (options.number - 1) + ')').remove();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment