Extjs自定义vtype [英] Extjs custom vtype

查看:348
本文介绍了Extjs自定义vtype的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用自定义vtype验证文本字段来过滤空白,例如:。
我在app.js中定义了我的自定义vtype(即使用mvc模式)。

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'],
        ....
    });

但是,Firebug显示此错误:

But, Firebug show this error:


TypeError:vtypes [vtype]不是函数

TypeError: vtypes[vtype] is not a function

我认为语法是正确的。但是,我不知道在哪里插入Vtype的代码。
有什么想法?
Thanks。

I would think that the syntax is correct. But, i dont know where insert the code of Vtype. any idea ?. Thanks.

推荐答案

在渲染表单前,我将自定义vtypes放入应用的控制器中。

I 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);
           }
       }
   }
   ...    
}

这篇关于Extjs自定义vtype的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆