setValue not working on label

according to the api, ui.label has a setValue function, so, the following should work, but doesn’t:

    webix.ready(function () {
        webix.ui({
            rows : [
                {
                    view  : 'label',
                    id    : 'label1',
                    label : 'one'
                },
                {
                    view  : 'button',
                    label : 'click',
                    width : 90,
                    click : function () {
                        $$('label1').setValue('two')
                    }
                }
            ]
        })
    })

Any reason?

just to add to this, if you use setHTML instead of setValue then it will work, UNLESS, you also set some css properties.
eg: if you set the alignment:

{
         view  : 'label',
          id    : 'label1',
          label : 'one',
          align: 'center'
}

then setHTML throws this error (on Chrome):

Uncaught TypeError: Cannot set property ‘display’ of undefined

Hello,

It seems that setValue is working for ui.label. http://webix.com/snippet/ff16e13c

As to setHTML and alignment - the control expects its template to be an element, not a text node and applies the styling to an element, which causes the error.

Moreover,

  • setHTML doesn’t change the label value, only appearance
  • getValue() return exactly what one stated via setValue()
  • if value is the same, setValue() method won’t cause label redrawing.

Thanks Helga, actually your snippet doesn’t work for me !
Try alternating between clicking button ‘two’ and button ‘three’ you’ll see that that button ‘two’ only works once, then stops working.

Actually, it works as expected - you set value “two” to a label, then set html “three”. Value remains the same - you can check it with the getValue() method. After that if you try to set the same value “two”, button won’t be redrawn as value hasn’t changed while setting other value will change the button’s appearance.

Please try the modified sample http://webix.com/snippet/47c2b31b.

I agree it’s a bit messy.

Definitely messy, after clicking setvalue, sethtml, a few times, you end up in a state where value = ‘two’, but the displayed text is ‘three’.

Seems like one should use setHtml instead of setValue, if you want to be sure that the displayed value in correct, no?

For now one should either use setHTML or setValue to avoid such ambiguity.