ramiromd
ramiromd

Reputation: 2029

Extjs custom vtype

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.

Upvotes: 3

Views: 7938

Answers (5)

KBIIX
KBIIX

Reputation: 911

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

Upvotes: 2

Abhinav Sahu
Abhinav Sahu

Reputation: 302

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.

Upvotes: 1

uncaught_exception
uncaught_exception

Reputation: 1078

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

Upvotes: 1

Vyacheslav Voronchuk
Vyacheslav Voronchuk

Reputation: 2463

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.

Upvotes: 0

darren102
darren102

Reputation: 2830

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.

Upvotes: 0

Related Questions