admin管理员组文章数量:1319006
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.
本文标签: javascriptExtjs custom vtypeStack Overflow
版权声明:本文标题:javascript - Extjs custom vtype - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742053227a2418160.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论