Results 1 to 4 of 4

Thread: Combobox problem with Ext 5.1

  1. #1
    Sencha User
    Join Date
    Feb 2013
    Posts
    4

    Default Combobox problem with Ext 5.1

    I had a problem with the combobox and Ext 5.1 (this example worked as expected with Ext 5.0.1)

    Code:
                {
                    xtype: 'combobox',
                    store: Mymodule.GENDER_CHOICES, // (store)
                    name: 'gender',
                    queryMode: 'local',
                    fieldLabel: translate('Gender'),
                    displayField: 'name',
                    valueField: 'value',
                    forceSelection: true,
                    bind: {
                        value: '{mainRecord.gender}'
                    },
                 }
    Mymodule.GENDER_CHOICES is a simple store created like this :

    Code:
    Ext.create('Ext.data.Store', {
      "fields": [
        "value",
        "name"
      ],
      "data": [
        {
          "name": translate("male"),
          "value": 1
        },
        {
          "name": translate("female"),
          "value": 2
        },
      ]
    })
    The field gender is defined like this :
    Code:
        {
          "name": "gender", 
          "type": "integer",
          "defaultValue": 1,
          "validators": [
            {
              "type": "presence"
            },
    
    
            {
              "list": [
                1,
                2
              ], 
              "type": "inclusion"
            }
          ]
        },
    And... it doesn't work.

    The combobox does the validation on the rawValue of the choice ("female" or "male"). I expected the validation to be performed on the "value" of the field (1 or 2).


    The only way I found to make the combobox work with Ext5.1 is to overload the isValid method in the field definition :
    Code:
                {
                    xtype: 'combobox',
                    store: Mymodule.GENDER_CHOICES, // (store)
                    //....
                     isValid: function() {
                        var me = this,
                        disabled = me.disabled,
                        validate = me.forceValidation || !disabled;
                   
                        return validate ? me.validateValue(me.getValue()) : disabled;
                    }
                }
    Is that normal?
    Is that what we want?
    Did I do something wrong?

  2. #2
    Sencha User joel.watson's Avatar
    Join Date
    Nov 2014
    Posts
    3,120
    Answers
    446

    Default

    Hi--

    I'm not sure what the issue is. When I put together a Fiddle using your code, it seems to behave the same in 5.0.1 as in 5.1.0. Can you take a look?

    Thanks
    Joel


  3. #3
    Sencha Premium Member
    Join Date
    Feb 2012
    Posts
    40
    Answers
    2

    Default

    Use `modelValidation: true` to reproduce (also in extjs 6!!!):

    https://fiddle.sencha.com/#fiddle/qoj

    My workaround is an override of `isValid` & `publishValue`:

    PHP Code:

    Ext
    .define('MyApp.form.field.ComboBox', {
        
    override'Ext.form.field.ComboBox',

        
    isValid: function () {
            var 
    me this,
                
    disabled me.disabled,
                
    validate me.forceValidation || !disabled;

            return 
    validate me.validateValue(me.getValue()) : disabled;
        },

        
    publishValue: function() {
            var 
    me this;
            if (
    me.rendered && !me.getErrors(me.getValue()).length) {
                
    me.publishState('value'me.getValue());
            }
        }
    }); 

  4. #4
    Sencha User lsdriscoll's Avatar
    Join Date
    Jan 2012
    Location
    Bournemouth, UK
    Posts
    30

    Default

    Thanks for the patch @chanand
    Last edited by lsdriscoll; 6 May 2016 at 3:25 AM. Reason: made it simpler
    Why did they have to go with CKEditor??

Tags for this Thread

Posting Permissions

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