Copy link to clipboard
Copied
try67 was nice enough to provide this script (see below). It works great but I noticed it allows me to enter text in the field. Don't want that. The field should only allow a dollar amount to be entered and accepted. Can someone show me how to modify this bit of script to not allow text? Thank you.
script:
if (event.value) {
event.value = "$" + util.printf("%,0.2f", event.value) + "/ per foot";
}
I've placed the script under Custom Format.
Copy link to clipboard
Copied
You'd need to add a custom Keystroke script. When you say you want to enter a dollar amount, do you want to allow cents as well?
Copy link to clipboard
Copied
hi George, yes I want to show the dollars and cents. As it is right now, I can do that. Like this, if I enter 25.58 the field shows $25.58 per foot. But, if I enter some text, the field shows the text and the "per foot". Not what I want to do. It doesn't make sense. I don't know how to modify the script to do as you're saying. Would I just place the script to the Keystroke window? Would modifying this script be too complicated?
Copy link to clipboard
Copied
No, you'd need to write a second piece of script to control what the user types.
Or modify the first strip to remove everything that isn't one of your legal 11 characters.
Copy link to clipboard
Copied
George and "Test Screen Name" are kind of correct.
If you just want to viszally display something, you don't need a Keystroke event script, and you can do the character filtering in the Format event.
HOWEVER, if you want to do something with the value, you will already have to make sure that only legal characters are entered. Otherwise, you will have garbage input into your further calculations.
A very simplistic approach is to make sure you work with a string, and then use the replace() function with an according Regular Expression.
In the Keystroke Event, you would use this script:
if (!event.willCommit) {
event.change = event.change.toString().replace(/[^\d.]/gim, "") ;
}
This will drop any entered character, except numbers, the minus sign and the period.
Then you can use the already mentioned script in the Format event.
Copy link to clipboard
Copied
Why not use event.rc in the Keystroke event to reject invalid values, instead of changing them?
Copy link to clipboard
Copied
Would work as well.