2012-11-16 90 views
3

即時嘗試使用自定義vtype驗證文本字段以過濾空白,例如:「」。 我在app.js中定義了我的自定義vtype(即時通訊使用mvc模式)。Extjs自定義vtype

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

但是,螢火顯示此錯誤:

TypeError: vtypes[vtype] is not a function

我認爲語法是正確的。但是,我不知道在哪裏插入Vtype的代碼。 有什麼想法? 謝謝。

+0

何時何地發生此錯誤? –

+0

當寫入字段.- – ramiromd

+0

如果您在控制檯「Ext.form.field.VTypes」中鍵入(應用程序加載後),是否有您的'descartarBlanco'條目? –

回答

0

可能是相同的問題,但與Ext.data.Types只有在類型名稱是大寫時才起作用。小寫字母會得到與您所看到的相似的信息。

0

您使用Ext.Loader,因此Ext.form.field.VTypes可以稍後重寫。嘗試在實際使用之前添加vtype定義。

+0

mmm即時通訊使用mvc模式,我把VType代碼放入app.js中,使用所有形式的自定義驗證器。那麼,sugest是否覆蓋了代碼? – ramiromd

1

我遇到了這個問題,試圖找到解決方案,因爲我面臨同樣的問題。當我將它添加到Ext.application中的'init:'時它工作正常。

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 
      } 
    }) 
0

您可以配置自己的電子郵件驗證。

xtype:'textfield',
fieldLabel: 'Email',
name: 'email',
maskRe: /[[email protected]+]/i,//You can change it acccording to your requirement.

+0

此代碼不會檢查字段中已存在的字符。 –

2

我把我的自定義vtypes放在我的應用程序的控制器上呈現窗體之前。

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