Created
April 19, 2013 10:01
-
-
Save Altreus/5419362 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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