0

I have a datagrid that contains data from different documents. The user can edit some of the columns. I want to restrict them to only be able to enter a number. I would like to do it from the client side instead of server side as that would mean checking 20 or more documents.

ok figured out what to do. Create a function to format the data with as red background if they enter a non-numeric or invalid value. Put the function in a scriptBlock and put the name in the formatter field for each column

function ValidNmbr(s)
{
var RegularExpression = new RegExp(/^\$?([1-9]{1}[0-9]{0,2}(\,[0-9]{3})*(\.[0-9]{0,2})?|[1-9]{1}[0-9]{0,}(\.[0-9]{0,2})?|0(\.[0-9]{0,2})?|(\.[0-9]{1,2})?)$/);<br/>
if(RegularExpression.test(s))
{
    return s;
}
else {
    return "<span style='background-color:red'>"+s+"</span>";
}
}
BenMorel
  • 34,448
  • 50
  • 182
  • 322
Kalechi
  • 15
  • 4
  • How do you implement the datagrid? Using a data table? – stwissel Nov 01 '12 at 17:05
  • It's the xpage ext libs' dojo data grid with a restservice to a view. Looking at the formatter to see about highlighting the errors. This is for an expense report so there is validation after they enter but would like to prevent the delay. – Kalechi Nov 06 '12 at 18:07
  • The Dojo grid [has data types](http://dojotoolkit.org/documentation/tutorials/1.6/working_grid/), so it takes care of number entries – stwissel Nov 07 '12 at 09:02

1 Answers1

0

Client side format enforcement can be bypassed (anyone having firebug), so you have to be clear it is only for the comfort of the user, not for the integrity of your data.

On the server side: you can have a entry field with a number mask. No code required -- might be the least work. If you want to do that client side:

  1. use the HTML5 attributes for number format
  2. use some helper to make older browsers behave
  3. consider to use a Dojo grid. It does nice validation

Hope that helps

Community
  • 1
  • 1
stwissel
  • 20,110
  • 6
  • 54
  • 101