Search code examples
extjs4

can't ascess to field in Ext.form.field.VTypes


This code is working:

    Ext.application({
    name: 'WebClient',
    autoCreateViewport: true,
    launch: function() {                
        Ext.apply(Ext.form.field.VTypes, {
            IPAddress:  function(v) {
                return /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(v);
            },
            IPAddressText: 'Некорректный IP Адресс',
            IPAddressMask: /[\d\.]/i
        });

        Ext.apply(Ext.form.field.VTypes, {
            port:  function(v) {
                function isNumber(n) {
                  return !isNaN(parseFloat(n)) && isFinite(n);
                }
                if (!isNumber(v)) return false;
                return (v>=0 && v<=65535)
            },
            portText: 'Порт 2 байта 0..65535',
            portMask: /[\d\.]/i
        });

    },
    models: ['Request','RPCLog','Connection']
});

But if I comment line autoCreateViewport: true, or set this property to false, the browser produces an error: Uncaught TypeError: Cannot read property 'field' of undefined. How to make Ext.form.field.VTypes available without autoCreateViewport:true?


Solution

  • I had the same issue, except that I was defining the custom VType in the view.

    Defining the VType inside the initComponent helped resolve the issue.

    initComponent : function(){
    
            // Add the additional 'advanced' VTypes
    
            Ext.apply(Ext.form.field.VTypes, {
                daterange: function(val, field) {