Results 1 to 4 of 4

Thread: Field validator cannot reference function in ViewController

    You found a bug! We've classified it as EXTJS-20559 . We encourage you to continue the discussion and to find an acceptable workaround while we work on a permanent fix.
  1. #1
    Sencha Premium Member
    Join Date
    Aug 2013
    Posts
    1

    Exclamation Field validator cannot reference function in ViewController

    ExtJS version : 6.0.1.250

    If using MVVM design, in the View I would like to have
    Code:
    {
       xtype: 'textfield',
       fieldLabel: 'Enter Value',
       reference: 'myField',
       bind: {
           value: '{dataModel.myValue}'
       },
       validator: 'myValidator'
    }
    With corresponding ViewController
    Code:
    myValidator: function( value ) {
      // some validation
    }
    I have been unable to make this work.

    I can put the function inline in the view. This works but breaks the MVVC design principles.

    Or if I want all the code in the ViewController, then something like this works.
    Code:
    onShow: function() {
      var me = this,
            myField = me.lookupReference('myField');
    
      myField.validator = Ext.bind( me.myValidator, me, [myField]);
    }
    
    myValidator: function(field) {
      var value = field.getValue();
    
       // some validation
    }
    Which gets very ugly when I have many fields for which I want custom validators.

    Tim.

  2. #2

    Default

    Thanks for the report! I have opened a bug in our bug tracker.

  3. #3

    Default

    As a workaround you can do something like this instead:
    Code:
    validator:function(){
                        this.up("form").getController().onValidate();
                    }

  4. #4
    Sencha User
    Join Date
    Aug 2015
    Location
    India
    Posts
    24

    Default

    Hi Alex,

    Even I am facing the same issue while using MVVM architecture.
    But getting controller reference from the view by calling getController() method is not a right way of coding right?
    I am not sure. I may be wrong.
    Instead, a custom event can be created; which can be triggered by the view class.
    Code:
    // controller class:
    init: function() {
        this.control({
            '#': {
                'validateField': 'validateFld'
            }
        });
    },
    
    
    validateFld: function(val) {
        // your code goes here
    }
    
    // view class:
    this.up('form').fireEvent('validateField', val);
    This way it works..!!

Similar Threads

  1. Replies: 1
    Last Post: 30 Jul 2014, 3:53 PM
  2. Replies: 1
    Last Post: 30 Jul 2014, 10:52 AM
  3. how to reference form from a validator
    By d1rty in forum Ext 2.x: Help & Discussion
    Replies: 0
    Last Post: 14 Aug 2008, 10:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •