controlkit.js icon indicating copy to clipboard operation
controlkit.js copied to clipboard

Syncing panel elements programatically

Open dyarbrough93 opened this issue 7 years ago • 2 comments

You mention here that the api is being updated allow for this and should have been available many months ago, though i still see no mention of this in the API other than controlKit.update(), which does not sync color or text fields. Is this available and just not documented? Or am i somehow missing it? This is a requirement for what I'm working on, so if I can't do this then I can't use ControlKit even though I really like what it has to offer.

dyarbrough93 avatar Apr 22 '17 20:04 dyarbrough93

I really need an answer to this question! The fact that some components (in my case a slider) does not reflect the changes that are being performed programmatically is an absolute deal breaker.

Any chance we'll get a controlKit.update() that work on ALL components any time soon?

stixan avatar Sep 28 '17 07:09 stixan

the problem is, only "output components" get updated

// controlkit/lib/component/Output.js

Output.prototype.update = function () {
    if(!this._update){
        return;
    }
    this._setValue();
};



// controlkit/lib/component/StringOutput.js

StringOutput.prototype._setValue = function () {
    // ....
    var textArea = this._textArea,
    // ....
    textArea.setProperty('value', textAreaString);
    // ....
};

workaround

const config = {key: 'foo'}

const control = new ControlKit()
control.my = {} // user data
control.my.panel = control.addPanel()

// add component
control.my.panel.addStringInput(config, 'key')

// get last component
control.my.ass = control._panels.slice(-1)[0]._groups.slice(-1)[0]._components.slice(-1)[0]

// set value
const newValue = 'bar'
config.key = newValue
control.my.ass._input.setProperty('value', newValue)

// or if you know the component position
control._panels[0]._groups[0]._components[0]._input.setProperty('value', newValue)

hackaround

modify ControlKit.prototype.update = function () { in controlkit/lib/ControlKit.js to also update input components

milahu avatar Dec 26 '19 12:12 milahu