Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 601
ramiromd Avatar asked Jun 11 '26 05:06

ramiromd


1 Answers

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);
           }
       }
   }
   ...    
}
like image 100
KBIIX Avatar answered Jun 13 '26 05:06

KBIIX



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!