PDA

View Full Version : Custom VType Used in Grid Field?



shaoen01
18 Feb 2012, 7:12 PM
Hi All,

I am using a grid and the roweditor plugin. I have my own custom vtype to validate for positive numbers that allows decimals as well. The value has to be >0. I tried to implement the vtype similar to the pre-defined vtype such as 'email' and 'url', etc onto my fields when someone is editing the row for validation purposes. But somehow it does not seem to work (i keep seeing an error which was defined by me below and i am sure the value entered is more than 0) and it can't seem to find out why. Below are my codes:



var positivenumberTest = /^\.?\d+$/g;
Ext.apply(Ext.form.field.VTypes, {
// vtype validation function
positivenumber: function(val, field) {
return positivenumberTest.test(val);
},
positivenumberText: 'Not a valid positibe number. Must be >0',
// vtype Mask property: The keystroke filter mask
positivenumberMask: /[\d\s:amp]/i
});


Code snippet to call the vtype


{
xtype: 'numbercolumn',
text: "Shipping Total",
dataIndex: 'shippingtotal',
width: 70,
renderer : 'usMoney',
hidden: false,
sortable: true,
field: {
xtype: 'numberfield',
vtype: 'positivenumber'
}

}


Thanks all!

shaoen01
18 Feb 2012, 7:16 PM
Added a screenshot, thanks!

shaoen01
25 Feb 2012, 7:37 AM
Has anyone encountered this before?

shaoen01
25 Feb 2012, 10:20 PM
I found this vtype that works and solved my issue, which i feel others might find it useful?


var positivenumberTest = /(^\d\d*\.\d*$)|(^\d\d*$)|(^\.\d\d*$)/;