Exemplo n.º 1
0
    def test_js_on_change_executes(self,
                                   bokeh_model_page: BokehModelPage) -> None:
        group = RadioButtonGroup(labels=LABELS)
        group.js_on_event(
            'button_click',
            CustomJS(code=RECORD("active", "cb_obj.origin.active")))

        page = bokeh_model_page(group)

        el = find_element_for(page.driver, group, ".bk-btn:nth-child(3)")
        el.click()

        results = page.results
        assert results['active'] == 2

        el = find_element_for(page.driver, group, ".bk-btn:nth-child(1)")
        el.click()

        results = page.results
        assert results['active'] == 0

        assert page.has_no_console_errors()
from bokeh.io import show
from bokeh.models import CustomJS, RadioButtonGroup

LABELS = ["Option 1", "Option 2", "Option 3"]

radio_button_group = RadioButtonGroup(labels=LABELS, active=0)
radio_button_group.js_on_event(
    "button_click",
    CustomJS(args=dict(btn=radio_button_group),
             code="""
    console.log('radio_button_group: active=' + radio_button_group.active, this.toString())
"""))

show(radio_button_group)
Exemplo n.º 3
0
dropdown_split = Dropdown(label="Split button", split=True, button_type="danger", menu=menu)
dropdown_split.js_on_event("button_click", CustomJS(code="console.log('dropdown(split): click ' + this.toString())"))
dropdown_split.js_on_event("menu_item_click", CustomJS(code="console.log('dropdown(split): ' + this.item, this.toString())"))

checkbox_group = CheckboxGroup(labels=["Option 1", "Option 2", "Option 3"], active=[0, 1])
checkbox_group.js_on_change('active', CustomJS(code="console.log('checkbox_group: active=' + this.active, this.toString())"))

radio_group = RadioGroup(labels=["Option 1", "Option 2", "Option 3"], active=0)
radio_group.js_on_change('active', CustomJS(code="console.log('radio_group: active=' + this.active, this.toString())"))

checkbox_button_group = CheckboxButtonGroup(labels=["Option 1", "Option 2", "Option 3"], active=[0, 1])
checkbox_button_group.js_on_event("button_click", CustomJS(code="console.log('checkbox_button_group: active=' + this.origin.active, this.toString())"))

radio_button_group = RadioButtonGroup(labels=["Option 1", "Option 2", "Option 3"], active=0)
radio_button_group.js_on_event("button_click", CustomJS(code="console.log('radio_button_group: active=' + this.origin.active, this.toString())"))

widget_box = Column(children=[
    button, button_disabled,
    toggle_inactive, toggle_active,
    dropdown, dropdown_disabled, dropdown_split,
    checkbox_group, radio_group,
    checkbox_button_group, radio_button_group,
])

doc = Document()
doc.add_root(widget_box)

if __name__ == "__main__":
    doc.validate()
    filename = "buttons.html"