Copy link to clipboard
Copied
Hello,
it is me again. 🙂
I am trying to reset a form when clicking a reset-button.
Currently i used the function resetForm(Fields) but i want to reset the fields to the default value which is given in the preferences/settings.
So i thought about looping all fields and put value to defaultValue but then my Acrobat freezes.
Previous Script:
var fieldstoteset = ["Field1", "Field2", "Field3"];
if(4==app.alert("The form will be resetted.\n\nAll data will be removed! Continue?",1,2)) {
this.resetForm(fieldstoteset );
this.getField("top").setFocus();
}
New Try:
if(4==app.alert("The form will be resetted.\n\nAll data will be removed! Continue?",1,2)) {
for (var i = 0; i < this.numFields; i++) {
var fieldname = getField(getNthFieldName(i);
this.getField(fieldname).name).value = this.getField(fieldname).defaultValue;
}
this.getField("top").setFocus();
}
Many thanks in advance for your hints 🙂
Copy link to clipboard
Copied
The "doc.resetForm()" function already does this. There is no need for an explicit script.
Copy link to clipboard
Copied
EDIT: Sorry, have a typing mistake in the new script:
if(4==app.alert("The form will be resetted.\n\nAll data will be removed! Continue?",1,2)) {
for (var i = 0; i < this.numFields; i++) {
var fieldname = getField(getNthFieldName(i));
this.getField(fieldname).value = this.getField(fieldname).defaultValue;
}
this.getField("top").setFocus();
}
Copy link to clipboard
Copied
The "doc.resetForm()" function already does this. There is no need for an explicit script.
Copy link to clipboard
Copied
Thank you very much, didn't knew i can fire the function without the field-names.
For the code i just needed to replace "doc" with "this" because otherwise it comes an error that doc is not defined.
Copy link to clipboard
Copied
I wrote the code as "doc.resetForm()" because the resetForm function is a member of the document object. The "this" is a Core JavaSript keyword that references the current object. It just so happens that it is the current document when used in a top level script in a document event, which is why all the sample code is written that way. But do not make the mistake of thinking that "this" is always the current document. It is not.