Login Register

[Grid] How to validate an input or use ValidationTextBox

Hello,

Is there a way to control what the user have typed in an editable cell ?
Is it possible to use ValidationTextBox as a cell editor ?

Ektor

formatter - for format validations

You could use the formatter attribute with the editable cell , if you are looking to validate the format of the input in to the cell.
dojox\grid\tests\test_edit.htm has samples on how to do that .

Formatter *just* format

The formatter just formats what is displayed into the cell.
If I use :

formatStr = function(inDatum) {
   if (inDatum.length > 4){
      return inDatum.substring(0, 4);
   }
   return inDatum;
}

When the focus is lost on the cell, the value displayed will be truncated to 4 chr, but the real value of the cell will be the original text exceeding the size contraints.
Also, formatter doesn't provide a way to notify errors as with ValidationTextBox.

Any other idea ???

Ektor.

I've tried this and it seems

I've tried this and it seems to work fine. :))

dojo.provide("myGridTextBox");
    dojo.declare("myGridTextBox",
        dijit.form.MappedTextBox,
        {
           validator: function(value,constraints){               
             var maReg = new RegExp( "\\w+") ;
             var texte = this.textbox.value;
             var resultat = texte.match( maReg ) ;
                    
             if ((resultat != null) &&
                 (resultat.length >= 0) &&
                 (resultat[0].length == texte.length)) {
                 return true;
             }
             else {
                return false;
             }
        }
        }
        );

        ...

        var view1 = {
                cells: [[
                   {name: 'Test2',
                    editor: dojox.grid.editors.Dijit,
                    editorClass: "myGridTextBox",
                    field: 'test2'
                    }
                   ]]
        };

Any better idea ???