I need a numeric field to accept percentage figure. I want to allow the user to enter the percentage figure in any format like:
7%
0.07
7
7.
7.0
To me, surprisingly, it was not straightforward !
This is what I have done:
1. Used Numeric Field with the following Patterns:
Display: num{zzzz9.9%}
Edit: num{zzzz9.9%}|num{zzzz9%}|num{zzzz9.%}
Validation <nothing>
Data: num{zzzz9.9%}
2. Used "validate" event, and added the following script:
if (this.rawValue != null) {
this.rawValue = Math.abs(this.rawValue);if (this.rawValue >= 1) { this.rawValue = this.rawValue / 100;}}if (this.rawValue == null || this.rawValue <= 1) true;elsefalse;
Now, the field is working as required.
Any other simpler method you can think of ?
Tarek.