Copy link to clipboard
Copied
Hello!
I would like to have a button on each page to only reset THAT page but first have a popup that asked are you sure you want to reset?
I found a JavaScript that has the poppup and works, but it resets the ENTIRE document.
if( app.alert({
cMsg: "Are you sure you want to clear this form?",
cTitle: "Reset Form Warning",
nIcon: 2,
nType: 2
}) == 4) {
this.resetForm();
}
Can someone help? I acually don't know how to write Javascript (just learning), so if you could explain what you write, I would LOVE that!
Copy link to clipboard
Copied
Identifying fields by page number is not the greatest technique. It's better to group fields based on the required functionality or data relationship. Then the fields can be manipulated in a way that is consistent with the forms intent, or the required data structure.
But if you must go by page you can use this function to identify all fields that are on a page.
// if bExclusive is true, then it only returns fields that are exclusive to this page
function GetFieldsOnPage(oDoc, nPage, bExclusive)
{
var aFldList = [], oFld,aPgs;
for(var i=0;i<oDoc.numFields;i++){
oFld = oDoc.getField(oDoc.getNthFieldName(i)));
aPgs = (typeof(oFld.page) == "number")?[oFld.page]:oFld.page;
if(bExclusive?aPgs.every(nPg=> nPg == nPage):aPgs.some(nPg=> nPg == nPage))
aFldList.push(oFld);
}
return aFldList;
}
Assuming that the name of the reset button is unique for the entire form, this code will return the page number the button is on.
var nPg = event.target.page;
Resetting the fields can be done in a couple of different ways, here's one just sets each field to it's default value.
GetFieldsOnPage(this,nPg,true).forEach(a=>a.value = a.defaultValue);
Here's code that uses the resetForm Function
this.resetForm.apply(this, GetFieldsOnPage(this,nPg,true).map(a=>a.name) );
Copy link to clipboard
Copied
Identifying fields by page number is not the greatest technique. It's better to group fields based on the required functionality or data relationship. Then the fields can be manipulated in a way that is consistent with the forms intent, or the required data structure.
But if you must go by page you can use this function to identify all fields that are on a page.
// if bExclusive is true, then it only returns fields that are exclusive to this page
function GetFieldsOnPage(oDoc, nPage, bExclusive)
{
var aFldList = [], oFld,aPgs;
for(var i=0;i<oDoc.numFields;i++){
oFld = oDoc.getField(oDoc.getNthFieldName(i)));
aPgs = (typeof(oFld.page) == "number")?[oFld.page]:oFld.page;
if(bExclusive?aPgs.every(nPg=> nPg == nPage):aPgs.some(nPg=> nPg == nPage))
aFldList.push(oFld);
}
return aFldList;
}
Assuming that the name of the reset button is unique for the entire form, this code will return the page number the button is on.
var nPg = event.target.page;
Resetting the fields can be done in a couple of different ways, here's one just sets each field to it's default value.
GetFieldsOnPage(this,nPg,true).forEach(a=>a.value = a.defaultValue);
Here's code that uses the resetForm Function
this.resetForm.apply(this, GetFieldsOnPage(this,nPg,true).map(a=>a.name) );
Copy link to clipboard
Copied
Thank you Thom, very useful script!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now