roinr
January 11, 2021, 9:23pm
1
I’ve create a custom widget and I’m trying to set its “disabled” property in a callback function:
ms = CustomMultiSelect(value=["a"], options=["a", "b"])
def callback(attr, old, new):
ms.disabled = True
ms.on_change('value', callback)
curdoc().add_root(ms)
When the callback is invoked I get the following error in the console:
Seems like it happens only when trying to set the “disabled” property. Other properties don’t cause this error.
Bryan
January 11, 2021, 9:28pm
2
Best guess: you would need to implement the abstract controls
method on your custom widget view to return all fo the HTML elements that need to have their disabled
property updated. See:
import {Widget, WidgetView} from "./widget"
import {toggle_attribute} from "core/dom"
import * as p from "core/properties"
export abstract class ControlView extends WidgetView {
model: Control
abstract controls(): Iterable<HTMLElement & {disabled: boolean}>
connect_signals(): void {
super.connect_signals()
const p = this.model.properties
this.on_change(p.disabled, () => {
for (const el of this.controls()) {
toggle_attribute(el, "disabled", this.model.disabled)
}
})
}
}
This file has been truncated. show original
If that’s not it, then you would need to provide actual code to investigate in order to speculate further.
Also, I should remind that it is always advised to include relevant version information in all questions.
roinr
January 12, 2021, 10:51am
3
Thanks @Bryan !
It didn’t work for me (maybe I did it wrong since I’m not so familiar with BokehJS).
I ended up creating a new enabled
property for the widget so I’ll use it instead. I figured it will be the easiest/fastest sufficient solution.
Also, I should remind that it is always advised to include relevant version information in all questions.
Right, sorry for that.