event.willCommit, JavaScript, Acrobar, event.rc
Copy link to clipboard
Copied
hello, I have a simple script that does not allow to insert anything but numbers. Unfortunately, I guess I don't understand how the willCommit event works. Until now, I thought that if(!event.willCommit) would rerun the script every time the field changed before committing the value. And event.willCommit (without the exclamation point) will run the script when the event is committed. However, the following script makes it impossible to fill the field at all (neither with numbers nor with any characters). What am I doing wrong? And could someone really explain to me how willCommit actually works?
var ff = /[0-9]+/g;
if(!event.willCommit){
event.rc = ff.test(event.value);
}
Copy link to clipboard
Copied
If you want to allow only numbers, you don't need keystroke script, you can format field as number.
Field formatted as number will only allow for numbers and decimal point.
Copy link to clipboard
Copied
The keystroke (or paste) value entered into the field is "event.change". The "event.value" contains the existing data in the field. Also, the RegEx pattern needs to restrict the test to entire entered data. Otherwise someone could paste "aa123bb" into the field and it would pass the test.
The script should be:
var ff = /^[0-9]+$/;
if(!event.willCommit){
event.rc = ff.test(event.change);
}
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
It's all described in the API Reference. Here's the description of the willCommit propery:
Verifies the current keystroke event before the data is committed. It can be used to check target form field
values to verify, for example, whether character data was entered instead of numeric data. JavaScript sets
this property to true after the last keystroke event and before the field is validated.

