javascriptcheckboxextjstextareasencha-touch-2

Extjs checkbox boxLabel color not changing


I have a checkbox along with a boxLabel and a textarea as shown below:

xtype: 'container',
items: [{
    {
      xtype: 'textarea',
      scrollY: true,
      screenX: true,
      height: 130,
      minHeight: 80,
      top: 10,
      width: 650,
      id: 'testDisplay',
      name: 'testDisplay',
      itemId: 'testDisplay',
      bind: {
         value: some text
      },
      listeners: {
         afterrender: function(cmp) {
            textAreaComp = me.down('#testDisplay');
            textAreaComp.setValue(someInfo);
            const myCheckBox = this.up('container').getComponent('testDisplayChkbox');
            this.el.down('textarea').dom.onscroll = function () {
               if (this.scrollHeight <= (this.scrollTop + this.offsetHeight)) {
                   myCheckBox.setDisabled(false);
                   myCheckBox.el.setStyle('color',red);
               }
            };
         }
      },
    },
    {
        xtype: 'checkboxfield',
        name: 'testDisplayChkbox',
        id: 'testDisplayChkbox',
        itemId: 'testDisplayChkbox',
        checked: false,
        boxLabel: someLabel,
    }
]

I am looking to get the outline of the checkbox and the text color of the boxLabel to change between two colors based when the text area is scrolled to the bottom. I have tried to use cls as well as setting the color dynamically as shown above but cannot get to change the colors of either the checkbox or the boxLabel. Any suggestions on how to get this to work?


Solution

  • In ExtJS a checkbox consists of more elements, including icon, box label etc. You can access these parts from the checkbox and use applyStyles to add extra styling. You can set colour to red initially, and then green when scrolled to bottom with the following code, and check out my updated fiddle.

    The code below is for ExtJS 4.2.1.

    Ext.application({
        name: 'Fiddle',
        launch: function () {
            Ext.create('Ext.container.Container', {
                renderTo: Ext.getBody(),
                layout: {
                    type: 'vbox',
                    align: 'stretch'
                },
                width: 500,
                items: [{
                    xtype: 'textareafield',
                    flex: 1,
                    value: 'Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?',
                    afterRender: function () {
                        const myCheckBox = this.up('container').getComponent('myCheckBox');
                        this.el.down('textarea').dom.onscroll = function () {
                            if (this.scrollHeight <= (this.scrollTop + this.offsetHeight)) {
                                myCheckBox.setDisabled(false);
                                myCheckBox.boxLabelEl.applyStyles({
                                    color: 'green'
                                });
                            }
                        };
                    }
                }, {
                    xtype: 'checkboxfield',
                    itemId: 'myCheckBox',
                    boxLabel: 'Lorem ipsum',
                    checked: false,
                    disabled: true,
                    afterRender: function () {
                        this.boxLabelEl.applyStyles({
                            color: 'red'
                        });
                    }
                }]
            });
    
        }
    });