Categories | Question details Back To List | ||
How to prevent non numeric character input in a grid Hi, I have a grid colone with a number format and it works fine. I've added a custom eXcells editor that validate the value and if not numeric sets it to 0. What I'd like to do is prevent any non numerical input by the user in the cell editor. So if you type letters for example they are not accepted by the cell editor. (kind of an input mask) Do you know any I can do that? Here's a sample function IsNumeric(n) { if(n*1==n) return true; else return false; } //extended simple editor (with number format support) //validate that the value is a numeric values else assign 0 function eXcell_edncl(cell){ this.base = eXcell_edn; this.base(cell) this.setValue = function(val) { if(!val || val.toString()._dhx_trim()=="" || !IsNumeric(val)) val="0" this.cell.innerHTML = this.grid._aplNF(val,this.cell._cellIndex); } } eXcell_edncl.prototype = new eXcell_edn; gridNumeroSerie = new dhtmlXGridObject('grid_container'); gridNumeroSerie = new dhtmlXGridObject('grid_container'); gridNumeroSerie.setHeader("Numéro,Qtée,UM1,Qtée,UM2"); gridNumeroSerie.setColTypes("ro,edncl,ro,edncl,ro"); gridNumeroSerie.setNumberFormat("0.000",1); gridNumeroSerie.setNumberFormat("0.000",3); gridNumeroSerie.setColSorting("int,int,str,int,str"); gridNumeroSerie.init(); Thank you Answer posted by Support on Nov 13, 2008 07:53 can be done as gridNumeroSerie.attachEvent("onEditCell",function(stage,id,ind){ if (stage == 1 && ind == 1) this.editor.obj.onkeypress=function(e){ //editor area if (some_check((e||event).keyCode) return true;//alloow return false; //deny } return true; }); Answer posted by David Charron on Nov 13, 2008 10:27 For futur reference here's how I did it. gridNumeroSerie.attachEvent("onEditCell",function(stage,id,ind){ if (stage == 1 && (ind == 1 || ind == 3)) this.editor.obj.onkeypress=function(e) { //editor area var ValidChars = "0123456789."; if (ValidChars.indexOf((String.fromCharCode((e||event).keyCode))) == -1) return false;//allow else return true; //deny } return true; }); |