im trying validate a textfield with a custom vtype to filter white spaces, ex: " ". I defined my custom vtype in the app.js (im using mvc pattern).
Ext.Loader.setConfig({
enabled : true,
paths: {
Ext: 'vendor/ext41/src',
My: 'app'
}
});
Ext.apply(Ext.form.field.VTypes, {
descartarBlanco: function(value) {
return /^\s+$/.test(value);
}
});
Ext.application({
name: 'CRUDManantiales',
appFolder: 'app',
controllers: ['Ui','Usuarios'],
....
});
But, Firebug show this error:
TypeError: vtypes[vtype] is not a function
I would think that the syntax is correct. But, i dont know where insert the code of Vtype. any idea ?. Thanks.
im trying validate a textfield with a custom vtype to filter white spaces, ex: " ". I defined my custom vtype in the app.js (im using mvc pattern).
Ext.Loader.setConfig({
enabled : true,
paths: {
Ext: 'vendor/ext41/src',
My: 'app'
}
});
Ext.apply(Ext.form.field.VTypes, {
descartarBlanco: function(value) {
return /^\s+$/.test(value);
}
});
Ext.application({
name: 'CRUDManantiales',
appFolder: 'app',
controllers: ['Ui','Usuarios'],
....
});
But, Firebug show this error:
TypeError: vtypes[vtype] is not a function
I would think that the syntax is correct. But, i dont know where insert the code of Vtype. any idea ?. Thanks.
Share Improve this question asked Nov 16, 2012 at 13:08 ramiromdramiromd 2,0298 gold badges33 silver badges64 bronze badges 5- When and where exactly do you get this error? – Dmitry Pashkevich Commented Nov 16, 2012 at 15:06
-
If you type in the console
Ext.form.field.VTypes
(after your app loads), is there yourdescartarBlanco
entry? – Dmitry Pashkevich Commented Nov 20, 2012 at 22:20 - Ext.form.field.VTypes shows the basics VTypes, but not show my custom VType "descartarBlanco" – ramiromd Commented Nov 23, 2012 at 12:25
-
Now that's mysterious. Do you actually define a vtype in your
app.js
file as posted above or you have it in another file? – Dmitry Pashkevich Commented Nov 23, 2012 at 12:49 - Both. First i try as posted above. How not work, wrote the code in a external js "validator.js" and include this before "app.js"- But the problem was the same ! – ramiromd Commented Nov 23, 2012 at 14:25
5 Answers
Reset to default 2I put my custom vtypes in my app's controller on before render form.
Ext.define('MyApp.controller.Main', {
extend: 'Ext.app.Controller',
...
init: function () {
var me = this;
me.control({
...
'form': {
beforerender: this.applyVtypes
},
...
})
},
...
applyVtypes: function() {
Ext.apply(Ext.form.field.VTypes, {
descartarBlanco: function(value) {
return /^\s+$/.test(value);
}
}
}
...
}
I reached this question trying to find a solution as I faced the same issue. It worked fine when I added it to 'init:' in Ext.application.
Ext.application({
...,
launch: function() {
...
},
init: function() {
Ext.apply(Ext.form.field.VTypes, {
descartarBlanco: function(value) {
return /^\s+$/.test(value);
}
}
console.log(Ext.form.field.VTypes); // for verification
}
})
You can configure your own email validation.
xtype:'textfield',
fieldLabel: 'Email',
name: 'email',
maskRe: /[a-z0-9_.-@+]/i,//You can change it acccording to your requirement.
Might be the same issue but with Ext.data.Types it only worked when the type name was uppercase. When lowercase would get a similar message as to what you are seeing.
You use Ext.Loader
so Ext.form.field.VTypes
can be overwritten somewhere later. Try to add your vtype definition just before you actually use it.