Results 1 to 3 of 3

Thread: Help with "publishes" property on components.

  1. #1
    Sencha Premium User
    Join Date
    Apr 2017
    Posts
    26
    Vote Rating
    0
      0  

    Default Answered: Help with "publishes" property on components.

    Hello,

    I have a question regarding the publishes property on components, that I'm hoping I can get some help with.

    To give an example, I have the following combobox:
    Code:
    Ext.define(''ComboTest", {
        extends: 'Ext.form.ComboBox'
        fieldLabel: 'Choose State',
        store: states,
        queryMode: 'local',
        displayField: 'name',
        valueField: 'abbr',
        renderTo: Ext.getBody()
    });
    What I want to do, is to use allowBlank based on a formula. Since it's not bindable, I'd like to make it bindable , and for this purpose if I understand correctly I have to use the publishes property. Based on my understanding this is what I wrote:
    Code:
    Ext.define(''ComboTest", {
        extends: 'Ext.form.ComboBox',
        viewModel: {
          formulas: {
            isTest: function () {
              return true;
           }
         }
        },
          config: {
            allowBlank: true
        },
        publishes: 'allowBlank',
        bind: {
          allowBlank: '{isTest}'
        },
        fieldLabel: 'Choose State',
        store: states,
        queryMode: 'local',
        displayField: 'name',
        valueField: 'abbr',
        renderTo: Ext.getBody(),
        setAllowBlank: function (val) {
          this.allowBlank = val;
       }
    });
    Is this the right way, or am I missing something here?

  2. use pubishes to easy access components config properties in binding statements/formulas by its reference.



    to make allowBlank bindable you need an override

    Code:
    Ext.define('MyOverrides.form.field.AllowBlank', {
        override: 'Ext.form.Field',
        setAllowBlank: function (value) {
            Ext.apply(this, {
                allowBlank: value
            });
        },
        getAllowBlank: function () {
            return this.allowBlank;
        }
    });

  3. #2
    Sencha Premium User wemerson.januario's Avatar
    Join Date
    Nov 2008
    Location
    Goiânia - GO, Brazil
    Posts
    832
    Answers
    14
    Vote Rating
    69
      0  

    Default

    use pubishes to easy access components config properties in binding statements/formulas by its reference.



    to make allowBlank bindable you need an override

    Code:
    Ext.define('MyOverrides.form.field.AllowBlank', {
        override: 'Ext.form.Field',
        setAllowBlank: function (value) {
            Ext.apply(this, {
                allowBlank: value
            });
        },
        getAllowBlank: function () {
            return this.allowBlank;
        }
    });
    Wemerson Januario @JanuarioCoder
    Novanti Tecnologia, Sencha MVP/ Ext JS Consultant
    ____________________________________________
    Hire me on UpWork:

    GitHub
    https://github.com/wemersonjanuario

    Treinamento e Consultoria Ext JS. QUALIFIQUE-SE JÁ!

  4. #3
    Sencha Premium User
    Join Date
    Apr 2017
    Posts
    26
    Vote Rating
    0
      0  

    Default

    Hello,

    Thank you for your answer it works. If I understand correctly your
    Quote Originally Posted by wemerson.januario View Post
    use pubishes to easy access components config properties in binding statements/formulas by its reference.
    statement, basically translates to, add setter/getter methods and then use publishes?

    Is your proposed solution the general approach for when we need to add setter/getter methods in existing properties of classes in Ext.js?

    Thank you,
    Sotiris.

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
  •