Expand my Community achievements bar.

Flexibile Data Entry Field for Percent Numbers.

Avatar

Level 8

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;

else

false;

Now, the field is working as required.

Any other simpler method you can think of ?

Tarek.

1 Reply

Avatar

Level 1

I used your script and settings and the script works but for some reason when I enter the number into the form it changes it to .4% instead of 36%.  It is still doing the computations correctly but just displaying .4 until you click on it and then it will display 36%. hope this makes sense.

Dave