Esempio n. 1
0
    def test_js_on_change_executes(self, single_plot_page):
        source = ColumnDataSource(dict(x=[1, 2], y=[1, 1]))
        plot = Plot(plot_height=400, plot_width=400, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0)
        plot.add_glyph(source, Circle(x='x', y='y', size=20))
        text_input = PasswordInput(css_classes=['foo'])
        text_input.js_on_change('value', CustomJS(code=RECORD("value", "cb_obj.value")))

        page = single_plot_page(column(text_input, plot))

        el = page.driver.find_element_by_css_selector('.foo input')
        enter_text_in_element(page.driver, el, "val1")

        results = page.results
        assert results['value'] == 'val1'

        # double click to highlight and overwrite old text
        enter_text_in_element(page.driver, el, "val2", click=2)

        results = page.results
        assert results['value'] == 'val2'

        # Check clicking outside input also triggers
        enter_text_in_element(page.driver, el, "val3", click=2, enter=False)
        page.click_canvas_at_position(10, 10)
        results = page.results

        assert results['value'] == 'val3'

        assert page.has_no_console_errors()
Esempio n. 2
0
    def test_js_on_change_executes(self, single_plot_page):
        source = ColumnDataSource(dict(x=[1, 2], y=[1, 1]))
        plot = Plot(plot_height=400, plot_width=400, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0)
        plot.add_glyph(source, Circle(x='x', y='y', size=20))
        text_input = PasswordInput(css_classes=['foo'])
        text_input.js_on_change('value', CustomJS(code=RECORD("value", "cb_obj.value")))

        page = single_plot_page(column(text_input, plot))

        el = page.driver.find_element_by_css_selector('.foo input')
        enter_text_in_element(page.driver, el, "val1")

        results = page.results
        assert results['value'] == 'val1'

        # double click to highlight and overwrite old text
        enter_text_in_element(page.driver, el, "val2", click=2)

        results = page.results
        assert results['value'] == 'val2'

        # Check clicking outside input also triggers
        enter_text_in_element(page.driver, el, "val3", click=2, enter=False)
        page.click_canvas_at_position(10, 10)
        results = page.results

        assert results['value'] == 'val3'

        assert page.has_no_console_errors()
Esempio n. 3
0
from bokeh.io import show
from bokeh.models import CustomJS, PasswordInput

password_input = PasswordInput(placeholder="enter password...")
password_input.js_on_change("value", CustomJS(code="""
    console.log('password_input: value=' + this.value, this.toString())
"""))

show(password_input)
Esempio n. 4
0
from bokeh.layouts import column, row
from bokeh.models import Button, CustomJS, PasswordInput, PreText, TextInput
from bokeh.plotting import output_file, show

output_file("using_password_input.html", title="Password Field")

USER = "******"
PASSWD = "Bok3h"

text = PreText(text="LOGIN TO KNOW THE SECRET:")
user = TextInput(placeholder="username", title=f"(UserName: {USER})")
password = PasswordInput(placeholder="password", title=f"(Password: {PASSWD})")
button = Button(label="GO!", width=150)

secret = PreText() # Secret information displayed if correct password entered

# Verify if the password typed is bokeh using a JS script
verify = CustomJS(args=dict(user=user, password=password, secret=secret), code="""
    secret.text = 'Wrong Password.';
    if (user.value == %r && password.value == %r) {
        secret.text = 'Correct Password. The Secret is 42.';
    }
""" % (USER, PASSWD))

password.js_on_change('value', verify)
button.js_on_event('button_click', verify)

layout = row(column(text, user, password, button), secret)

show(layout)