change the format of several fields in one step
Copy link to clipboard
Copied
I have a problem: i generate many pdf-formulars for many companies. I often have to change the format for over 50 fields at the same time. 50 fields will change from standard to integer format. Sometimes i have to change 50 fields from integer format with two decimal places to one decimal place.
How can i do that for several fields at the same time? Currently i change one filed by another. And that is no clean solution!
Best regards and thanks for your help
Copy link to clipboard
Copied
Paste this script in the JS Console, select all, and hit the Enter key:
for (var i = 0 ; i < this.numFields ; i++) {
var oFld = this.getField(this.getNthFieldName(i));
if ((oFld.type == "text") && (/total/.test(oFld.name))) {
oFld.setAction("Format","event.value = util.printf(\"%,2.0f\",event.value) ;");
}
}
It will change the Format of all text fields whose name contains total like this:
You can assign the format you want by setting printf:
Copy link to clipboard
Copied
I am trying to use the code above to change multiple text boxes at the same time from integer to 1 decimal point but it doesn't seem to work. The code I am using is below and all I have changed is for the file name to contain 'TestCPL' and the format from '%,2.0f' to %,2.1f (1 decimal point).
I have then selected all the fields on the page and hit enter but nothing seems to change in the field names that contain TestCPL. Can you please tell me what I am doing wrong?
Copy link to clipboard
Copied
You don't need to select the fields. You need to select the code in the JS Console and press Ctrl+Enter to execute it.
Copy link to clipboard
Copied
Thank you for responding.
I now seem to get the message 'undefined' under the code after I execute it
You can see the field names in the screenshot below and there are definitely a number of them in the first two rows that contain 'TestCPL' as part of the name.
Copy link to clipboard
Copied
"undefined" is not an error, the opposite, actually.
Check if the fields were actually edited.
Copy link to clipboard
Copied
They didn't change. My fields are currently set to zero decimal points and I am trying to set them to 1 decimal point. After executing that code they still remain at zero decimal points.
Copy link to clipboard
Copied
Daphne5C23 since it's a grid of fields you don't need to use a script.
Remove all fields except the first one, set the Format, then right-clic on the field and use "Create multiple copies".
This should take about 30 seconds.
Copy link to clipboard
Copied
Thanks for your suggestion. I do use the 'Create Multiple Copies' function when starting a form from scratch but sadly that is not an option for me on this occassion.
I actually have several existing forms to amend, each one with many fields in a grid pattern. Almost all of those fields contain individual validation scripts checking target values against actual values and formatting the text colour accordingly so if I used the create multiple copies method I would then have to amend all those validation scripts individually instead so it would actually take several hours.
Copy link to clipboard
Copied
That's because the code you got will not set the built-in Number option of the Format tab.
Try this:
oFld.setAction("Format", "AFNumber_Format(1, 0, 0, 0, \"\", false)");
oFld.setAction("Keystroke", "AFNumber_Keystroke(1, 0, 0, 0, \"\", false)");
Copy link to clipboard
Copied
That works perfectly! Thank you so much for all your help.
Copy link to clipboard
Copied
Edited.
Copy link to clipboard
Copied
It's possible to change the format of the fields to currency after it is calculated with out going into the formatting console?
![](/skins/images/FC087885B0C83B45128AF5065A4AB513/responsive_peak/images/icon_anonymous_message.png)
![](/skins/images/FC087885B0C83B45128AF5065A4AB513/responsive_peak/images/icon_anonymous_message.png)