$.event.special.inputchange = {
setup: function () {
var self = this, val;
$.data(this, 'timer', window.setInterval(function () {
val = self.value;
if ($.data(self, 'cache') != val) {
$.data(self, 'cache', val);
$(self).trigger('inputchange');
}
}, 20));
},
teardown: function () {
window.clearInterval($.data(this, 'timer'));
},
add: function () {
$.data(this, 'cache', this.value);
}
};
function getDataForAccount(){
var ajax_url = "index.php?module=EcmInvoiceOuts&action=javahelper&to_pdf=1";
var params = {
job : 'getDataForAccount',
id : $('#parent_id').val(),
};
$.ajax({
type : "POST",
url : ajax_url,
dataType : "json",
async : false,
success : function(data) {
console.log(data);
if(data[0].tele!=''){
console.log(data.tele);
$('#InputsWrapper').append('
|  |
');
}
if(data[0].email!=''){
$('#InputsWrapperMail').append(' |  |
');
}
},
data : params
});
}
$(document).ready(function() {
$('#parent_id').on('inputchange',
function () {
$(".loading_panel").css("display", "block");
setTimeout(function () {
getDataForAccount();
}, 1000);
});
var MaxInputs = 10; //maximum input boxes allowed
var InputsWrapper = $("#InputsWrapper"); //Input boxes wrapper ID
var AddButton = $("#AddMoreWWWBox"); //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);
$( "div input[name='telephones_id[]']" ).first().val(obj.id);
} else { // rest
$(InputsWrapper).append(' |  |
');
}
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(' |  |
');
x++; //text box increment
}
return false;
});
$("body").on("click",".removeclass", function(e){ //user click on remove text
console.log("x1: " +x);
if( x > 1 ) {
$(this).closest('tr').remove();//remove text box
x--; //decrement textbox
}
return false;
})
var MaxInputs1 = 10; //maximum input boxes allowed
var InputsWrapper1 = $("#InputsWrapperMail"); //Input boxes wrapper ID
var AddButton1 = $("#AddMoreMailBox"); //Add button ID
var x1 = InputsWrapper1.length; //initlal text box count
var FieldCount1=1; //to keep track of text box added
var emaillists = $.parseJSON($("input[name='emails_list']").val()); // get and decode json object
$.each(emaillists, function(idx, obj) { // add existing elements
FieldCount1++; //text box added increment
//add input box
if(idx == 0 ){ // to first element
$( "div input[name='emails[]']" ).first().val(obj);
$( "div input[name='emails_id[]']" ).first().val(obj.id);
} else { // rest
$(InputsWrapper1).append(' |  |
');
}
x1++; //text box increment
});
$(AddButton1).click(function (e) //on add input button click
{
if(x1 <= MaxInputs1) //max input box allowed
{
FieldCount1++; //text box added increment
//add input box
$(InputsWrapper1).append(' |  |
');
x1++; //text box increment
}
return false;
});
$("body").on("click",".removeclass1", function(e){ //user click on remove text
console.log("x1: " +x1);
if( x1 > 1 ) {
$(this).closest('tr').remove();//remove text box
x1--; //decrement textbox
}
return false;
})
});