Copy link to clipboard
Copied
I have two check boxes that I want to spawn templates when checked, and delete those pages when unchecked. I have no issue spawning the templates, but I am unable to determine the page number once they are spawned to be able to delete these once unchecked.
I understand the pages start at 0, but the output does not make sense when I print to console. The three templates are hidden.
I check checkbox1 then checkbox2, and uncheck in the same order and the console prints the following for the page numbers:
temp1pages=0
temp2pages=-1,-11
temp3pages=0
My code currently is this for checkbox1:
if(this.getField("Checkbox1").isBoxChecked(0) == true){
var temp1 = this.getTemplate("template1");
temp1.spawn();
}
else{
var temp1pages = this.getField("template1_field").page+1;
this.deletePages(temp1pages);
}
and for checkbox2:
if(this.getField("Checkbox2").isBoxChecked(0) == true){
var temp2 = this.getTemplate("template2");
var temp3 = this.getTemplate("template3");
temp2.spawn();
temp3.spawn();
}
else{
var temp2pages = this.getField("template2_field").page+1;
this.deletePages(temp2pages);
var temp3pages = this.getField("template3_field").page+1;
this.deletePages(temp3pages);
}
Copy link to clipboard
Copied
What does you display in the console?
Copy link to clipboard
Copied
Because you choose not to rename the fields they are duplicates of each other. That means the page property returns an array of numbers, not just one number. The page number of a field that's located on a hidden template page is -1, which is what you're seeing as the first value of temp2pages. The second value is the page number of the spawned version, which is what you should use in your code.