Set up 2 buttons on your template called "SpawnButton" and "DeleteButton". The spawn button will be visible or non-printable, while the delete button will be hidden. The script in the spawn button will:
1) Spawn the page after the current page.
2) Advance the focus to the spawned page.
3) Hide the original spawn button.
4) Display the spawn button on the spawned page.
5) Display the delete button the spawned page.
The delete button will:
1) Delete the current page.
2) Advance the focus to previous page (the one before the deleted page).
3) Show the spawn and delete buttons on this page (unless it is the original page, in which case it will only show the spawn button.
This will ensure only one spawn button is visible at one time, which will spawn the current page after the current page and only one delete button is visible at one time to delete the current page. This user will be forced to spawn and delete pages in order. In this example the template name is "MyTemplate". This is the spawn button script:
var sb=event.target.name;
var db=event.target.name.replace(/Spawn/,"Delete");
this.getField("SpawnButton").display=display.noPrint;
this.getField("DeleteButton").display=display.noPrint;
this.getTemplate("MyTemplate").spawn ({nPage:this.pageNum+1,bOverlay:false});
this.getField("SpawnButton").display=display.hidden;
this.getField("DeleteButton").display=display.hidden;
this.getField(sb).display=display.hidden;
this.getField(db).display=display.hidden;
this.pageNum=this.pageNum+1;
This is the delete button script:
var pg=this.pageNum
this.pageNum--;
this.deletePages(pg,pg);
for(var i = this.numFields - 1; i > -1; i--)
{
var fieldName = this.getNthFieldName(i);
if (this.getField(fieldName).page==this.pageNum &&
this.getField(fieldName).name!="DeleteButton"&&
(/SpawnButton/.test(this.getField(fieldName).name) ||
/DeleteButton/.test(this.getField(fieldName).name)))
{this.getField(fieldName).display=display.noPrint}
}