I am trying to Add the ability to Remove a field on my form with Javascript but It isn't working. I have commented out my Remove field below. How can I fix it?
$(document).ready(function() {
var max_fields = 10; //maximum input boxes allowed
var wrapper = $(".input_fields_wrap"); //Fields wrapper
var add_button = $(".add_field_button"); //Add button ID
var x = 1; //initlal text box count
$(add_button).click(function(e){ //on add input button click
e.preventDefault();
if(x < max_fields){ //max input box allowed
x++; //text box increment
$(wrapper).append("<div><select name='tournament_id_" + x + "'> <%=j(options_from_collection_for_select(Tournament.all.where(tour_id: 1), 'id', 'event'))%></select></div>")
// <a href="#" class="remove_field">Remove</a></div>'") //add input box
}
});
$(wrapper).on("click",".remove_field", function(e){ //user click on remove text
e.preventDefault(); $(this).parent('div').remove(); x--;
})
Aucun commentaire:
Enregistrer un commentaire