Skip to content

Instantly share code, notes, and snippets.

@joice
Created February 20, 2014 20:38
Show Gist options
  • Save joice/9122724 to your computer and use it in GitHub Desktop.
Save joice/9122724 to your computer and use it in GitHub Desktop.
$(".add-new-phone-number").on('click',function(e){
e.preventDefault();
alert($(this).sigbli)
if($("div[id^='phone_number_']").length < 4 ){
$(this).remove(); //remove the add link from current text box
var id = $("div[id^='phone_number_']").length;
var input_phone_id = 'destination_phones_attributes_' + id + '_number'
var input_phone_name = 'destination[phones_attributes][' + id + '][number]'
var append_data = '<div id="phone_number_'+id+'"><div class="left"><input id="'+input_phone_id +'" type="text" name="'+input_phone_name +'" /></div><div class="right"><a class="add-new-phone-number" href="#">Adicionar número</a></div></div>';
$("#phone_numbers").append(append_data);
} else {
alert("Maximum 4 number are allowed");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment