/*var $container = $('.container');
var $row = $('.urlrow');
var $add = $('#addButton');
var $remove = $('#removeButton');
var $focused;
$container.on('click', 'input', function () {
$focused = $(this);
});
$add.on('click', function () {
alert($row.clone().toSource());
var $newRow = $row.clone().insertAfter('.urlrow:last');
$newRow.find('input').each(function () {
this.value = '';
});
});
$remove.on('click', function () {
if (!$focused) {
alert('Select a row to delete (click en input with it)');
return;
}
var $currentRow = $focused.closest('.urlrow');
if ($currentRow.index() === 0) {
// don't remove first row
alert("You can't remove first row");
} else {
$currentRow.remove();
$focused=null;
}
});
*/
$(document).ready(function(){
var maxField = 10; //Input fields increment limitation
var addButton = $('.add_button'); //Add button selector
var wrapper = $('.field_wrapper'); //Input field wrapper
var fieldHTML = '<div class="input-group col-md-12 col-sm-12" style="margin-bottom:10px"><input name="topic_urls[]" id="" placeholder="Topic Urls" value="" class="form-control col-md-9 col-sm-7" autocomplete="off" type="text"><a href="javascript:void(0);" class="remove_button btn btn-danger col-md-3 col-sm-5" title="Remove field" style="line-height: 23px;">Remove</a></div>';
//New input field html
var x = 1; //Initial field counter is 1
$(addButton).click(function(){ //Once add button is clicked
if(x < maxField){ //Check maximum number of input fields
x++; //Increment field counter
$(wrapper).append(fieldHTML); // Add field html
}
});
$(wrapper).on('click', '.remove_button', function(e){ //Once remove button is clicked
e.preventDefault();
$(this).parent('div').remove(); //Remove field html
x--; //Decrement field counter
});
});