Files
crm.twinpol.com/modules/Accounts/js/Telephones.js
2025-05-12 15:45:17 +00:00

47 lines
2.0 KiB
JavaScript

$(document).ready(function() {
console.log('ten plik');
$('.loading_panel').hide();
var MaxInputs = 10; //maximum input boxes allowed
var InputsWrapper = $("#InputsWrapper2"); //Input boxes wrapper ID
var AddButton = $("#AddMoreWWWBox2"); //Add button ID
var x = InputsWrapper.length; //initlal text box count
var FieldCount=1; //to keep track of text box added
var weblists = $.parseJSON($("input[name='telephones_list']").val()); // get and decode json object
$.each(weblists, function(idx, obj) { // add existing elements
FieldCount++; //text box added increment
//add input box
if(idx == 0 ){ // to first element
$( "div input[name='telephones[]']" ).first().val(obj.telephone);
$( "div input[name='telephones_id[]']" ).first().val(obj.id);
} else { // rest
$(InputsWrapper).append('<tr><td><input type="hidden" value="'+obj.id+'" name="telephones_id[]"><input type="text" size="30" name="telephones[]" id="field_'+ FieldCount +'" value="'+obj.telephone +'"/></td><td><a href="#" class="removeclass"><img class="id-ff-remove" name="0" src="index.php?entryPoint=getImage&amp;themeName=Sugar5&amp;imageName=id-ff-remove.png"></a></td></tr>');
}
x++; //text box increment
});
$(AddButton).click(function (e) //on add input button click
{
if(x <= MaxInputs) //max input box allowed
{
FieldCount++; //text box added increment
//add input box
$(InputsWrapper).append('<tr><td><input type="hidden" value="" name="telephones_id[]"><input type="text" size="30" name="telephones[]" id="field_'+ FieldCount +'" value=""/></td><td><a href="#" class="removeclass"><img class="id-ff-remove" name="0" src="index.php?entryPoint=getImage&amp;themeName=Sugar5&amp;imageName=id-ff-remove.png"></a></td>,/tr>');
x++; //text box increment
}
return false;
});
$("body").on("click",".removeclass", function(e){ //user click on remove text
if( x > 1 ) {
$(this).closest('tr').remove();//remove text box
x--; //decrement textbox
}
return false;
})
});