Hello everyone!
I need a little help. I have been following the advice in the forum located here -
How do you spawn a template from a button on an already spawned template and rename the field on it? (JavaScript)
I have used the advice in the forum and had great results. Recently the buttons have behaved erratically. (new update?)
The add code presented does a brilliant job of insuring the add page button is the last button to be displayed therefore eliminating the possibility of linked fields -
this.getField("Button1").display=display.noPrint; var a = this.getTemplate("newpage"); a.spawn({nPage: pageNum + 1, bRename: true, bOverlay: false}); this.getField("Button1").display=display.hidden; event.target.display=display.hidden; this.pageNum=this.pageNum+1; |
however the delete button code has given me errors. (bad parameter) Additionally depending on where i hit the delete button will cause the spawn button to re appear not as the last button on the last page. It will be in addition to the spawn last button on the last spawned page. This can cause the error described with the bRename: true
This has the potential to cause the pages to be linked.
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} }
var num=0; for(var i = this.numFields - 1; i > -1; i--) { var fieldName = this.getNthFieldName(i); if (/SpawnButton/.test(this.getField(fieldName).name)) {num=num+1;} }
if (num==1) {this.getField("SpawnButton").display=display.noPrint} else {this.getField("SpawnButton").display=display.hidden} |
It looks like the fix is this code on the add button -
var sb=event.target.name; var db=event.target.name.replace(/Spawnbutton/,"Deletebutton");
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; |
However it will only show the last page for spawn and delete buttons and will not work for my application.
Is there any way to use a code that will offer the end user to delete any page while keeping the last spawn button only?
For some reason you add 4 pages with the original code and delete the 3rd page you will get a second spawn button.
Any help would be greatly appreciated.
[Question moved to the Acrobat JavaScript forum. -Mod.]