PDA

View Full Version : Editable Grid, RegExp and Copy Paste



marchalx
11 Oct 2012, 2:19 AM
Hello,

I'd like to create a grid with the first column of the grid which is editable (documents name for example).

Yet, i have a regular expression on this name (i'd like to ban forbidden caracters such as ' " etc).

With a regExp, all works, except in the case where i copy paste a string with forbidden characters, the string is copied without control... I tried to use Vtype but this is not working. Does anyone have a idea of how can i use vtype for an editable grid or another solution (event validate edit?)?



// Vtype for name filter.
Ext.apply(Ext.form.field.VTypes, {
onlyA: function(name) {


var onlyA = new RegExp('[a]');


return onlyA.test(name);


},


onlyAText: 'only A available'


});

// by having a mask in the editor, regExp works but not copy paste...


//var mask = new RegExp('[a]');


this.nameColumn = {
header : 'Name',
editor : {
//maskRe : mask,
allowBlank: false,
// this code does not work...

vtype: 'onlyA'
},
// this code does not work either...


//vtype: 'onlyA',

width : 130,
sortable : true,
menuDisabled :true,
dataIndex: 'name'
};

mitchellsimoens
11 Oct 2012, 3:53 AM
Ext JS 3 or 4 so I can move this to the appropriate forum so you can get help?

marchalx
11 Oct 2012, 4:08 AM
Oh sorry i am new on this forum... For ExtJS 4 !

marchalx
12 Oct 2012, 1:11 AM
Okay, I found a satisfying way to solve my problem. I used a validator in the editor instead of vtypes



//My mask
var mask = new RegExp('aaaaaa');


// Name Colum
// ----------
this.nameColumn = {

header : 'Name',


editor : {


allowBlank: false,
validator: function(val)


{


if (!Ext.isEmpty(val) && !mask.test(val) )


{


return true;


}


else
{

return "Unvalid";


}


}


},
width : 130,
sortable : true,
menuDisabled :true,
dataIndex: 'name'

};