Copy link to clipboard
Copied
Hi all, another newbie question. I'm trying to set the formatting of many "Number" fields to "Custom" with a custom javascript. Basically what is posted by Max here. However, this method only works for me if the fields are already set to "Custom". Is there a way to set the formatting to "Custom" in the javascript?
Here is my test code (note that this code works as expected only if the field already has a custom formatter):
var myFields = ["difference.1", "difference.2", "difference.3"];
for (var i = 0; i < myFields.length; i++) {
this.getField(myFields[i]).setAction("Format", "event.value = util.printf(\"$%,0.0f\",event.value);");
}
Any help much appreciated.
- Mark
No, but it's not needed. I tried your code and saw the same result as you described, but I know what's causing it.
You see, the Number format is not just a Format event. It's also a Keystroke event (to prevent the user from entering letters into the field, for example). So unless you overwrite that, too, the hidden code used when you selected Number remains in tact, and the application still thinks the field is set to Number.
So add this line to your code to overcome that:
this.getField(myFiel
...Copy link to clipboard
Copied
No, but it's not needed. I tried your code and saw the same result as you described, but I know what's causing it.
You see, the Number format is not just a Format event. It's also a Keystroke event (to prevent the user from entering letters into the field, for example). So unless you overwrite that, too, the hidden code used when you selected Number remains in tact, and the application still thinks the field is set to Number.
So add this line to your code to overcome that:
this.getField(myFields[i]).setAction("Keystroke", "");
Copy link to clipboard
Copied
Just the sort of info I was hoping for! Thanks very much.
- Mark