i used reactjs to make input field that has a "plus" sign at the end and when clicked, it adds another input field... but my problem is when I remove the input field, then add again, it keeps multiplying... please check my code and try it... really need your help guys thanks in advance
addInput: 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><input class="form-control categ-field" type="text" name="category[]" placeholder="Category" required> <a href="javascript:void(0);" class="remove_button" title="Remove field"><i class=" glyphicon glyphicon-minus-sign text-yellow"></i></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
});
},
render: (){
return React.createElement(
"div",
{ className: "field_wrapper" },
React.createElement("input", { type: "text", name: "category[]", className: "form-control categ-field", placeholder: "Category" }),
React.createElement(
"a",
{ className: "add_button", title: "Add field", href:"javascript:void(0);", onClick:this.addInput},
React.createElement("i", { className: "glyphicon glyphicon-plus-sign text-green" })
)
)
}