Copy link to clipboard
Copied
I am creating calibration certificates, my fields are set as numerical values, but I cannot leave a blank field when data is not available. How can I default the blank fields with "--" using javascript?
Copy link to clipboard
Copied
I would set the field's format to "Custom" and write a custom format script that displays the symbols "--" when empty an the formatted number when number when not blank.
// Custom format field set to format on "Custom";
if(event.value == "")
{
event.value = "--";
} else {
event.value = util.printf("%,2 1.2f", event.value);
}
If you want the field to only accept numbers then you will need to write a custom keystroke script.
Copy link to clipboard
Copied
You can set the fields' default values to "--", under Properties - Options.
Copy link to clipboard
Copied
Doesn't work since the field format is numbers with 2 decimals
Copy link to clipboard
Copied
I would set the field's format to "Custom" and write a custom format script that displays the symbols "--" when empty an the formatted number when number when not blank.
// Custom format field set to format on "Custom";
if(event.value == "")
{
event.value = "--";
} else {
event.value = util.printf("%,2 1.2f", event.value);
}
If you want the field to only accept numbers then you will need to write a custom keystroke script.
Copy link to clipboard
Copied
Not sure what you are trying to do, are you calculating also in this field and therefore cant have zero? or do you just want to show the field blank, this way you can keep the formatting by just making the 0 white text and if the value is >0 it will be black
if(event.value && event.value <= 0)
{
event.target.textColor = color.white;
}
else
{
event.target.textColor = color.black;
}
Copy link to clipboard
Copied
Zero is not a blank value. It could be a real computed value.
The code I provided works in a numeric field set to 2 decimal places with a calculated value.
Copy link to clipboard
Copied
I agree, your code is the correct answer but the description was unclear what he meant by blank field, it depends on what he is doing with the entries to the fields assuming that sometimes the fields may have numerical entries 🙂
Mike
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more