SID-02412: Numeric Only - Form Field Template Element
| Status: |
Answered |
TWiki version: |
6.1.0 |
Perl version: |
Perl 5.30.0 |
| Category: |
CategoryForms |
Server OS: |
linux (Kernel version: 2.6.32-754.15.3.el6.x86_64) |
Last update: |
5 years ago |
Is there currently a way (or is one coming/proposed) to have a Numeric Only Form Field Type. One that would either restrict the file to numbers only --or-- numbers plus associated characters like a plus sign (+), minus sign (-), a decimal point (.) and a comma (,).
At this time, we have a form that asks for "Number of Days," for which we want only numeric values. For some reason, people enter values like "1.5 days" or "22 days", instead of just 1.5 or 22 respectively. No matter how much training we give them and how many reminders we send out, we still get non-numeric input.
Any help would be appreciated. Thanks.
--
Bob Mellinger - 2019-08-06
Discussion and Answer
As far as I can say, TWiki's own type system does not allow to restrict text input (and new releases don't come that often), so I can only suggest workarounds:
- HTML itself allows to restrict the values of
input fields with input type="number". I usually write my own HTML forms for applications, so this is often the way I go.
- JavaScript validation could either reject the non-numeric stuff or silently drop it.
- The TWiki stuff evaluating the field might also be able to strip units, maybe even automagically, given that in Perl the numeric value of "22 days" is just 22.
--
Harald Jörg - 2019-08-10
If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.