Copy link to clipboard
Copied
On my form I have several numerical fields that must be completed. I checked the "Required" property box, but I don't see any benefit. So I used a "On Blur" script type with the javascript below. This works but the function fires 3 times before the cursor is back in the field for correction. Below is my script.
var oal = this.getField("OAL");
if (oal.value == 0)
{
app.alert('Must complete Over-All-Length field!');
oal.setFocus();
}
Copy link to clipboard
Copied
The "required" property is only used when the file is submitted.
What exactly are you trying to achieve? Do you want to prevent the user from entering "0" into this field?
Copy link to clipboard
Copied
Yes, exactly. I have certain fields that contain measurement data and they can never be 0. So I was trying to validate their entry as they go along.
Tom
Copy link to clipboard
Copied
Use a custom validation script. You'll have to allow a blank value to the field can be reset to blank, so the script could be something like:
// Custom validation script
// The the field value is not blank and evaluates 0...
if (event.value && +event.value === 0) {
// Disallow the entry
event.rc = false;
// Inform the user
app.alert("Please enter a non-zero value.", 3);
}
Copy link to clipboard
Copied
I tried George's code as a validation script, however this code does not stop the Operator from entering by the field without entering anything. That seems like the most likely Operator error. Also is there a way to put the cursor back into that field. So far the cursor moves to the next field after the app alert.
Here is my code:
var oal = this.getField("OAL");
if (event.value && +event.value === 0)
{
event.oal = false;
app.alert('Must complete Over-All-Length field',3);
}
Copy link to clipboard
Copied
try adding this code.
event.target.setFocus();
Copy link to clipboard
Copied
I added the line of code suggested by Thom. It did not put the cursor back into the field to be completed. Additionally it still does not fire if the Operator simply tabs through the field. So, I tried a few things and this is where I am at.
1. I put a default value of 0.00 in the field so that the Operator cannot tab through the field without an error.
2. I changed the coding from a custom validation script to a Javascript using the On Blur trigger. This stops the cursor from moving on to the next field, however the app alert fires 3 times before control is returned to the OAL field. But it does work, if I could make it fire only once.
Here is my current code:
On Blur: Javascript
var oal = this.getField("OAL");
if (event.value && +event.value === 0)
{
event.oal = false;
app.alert('Must complete the Over-All-Length field!,3);
event.target.setFocus();
}