Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure param callbacks initialized #1439

Merged
merged 2 commits into from
Jun 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions panel/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,23 @@ def widget_type(cls, pobj):
return cls._mapping[t](pobj)
return cls._mapping[t]

def select(self, selector=None):
"""
Iterates over the Viewable and any potential children in the
applying the Selector.

Arguments
---------
selector: type or callable or None
The selector allows selecting a subset of Viewables by
declaring a type or callable function to filter by.

Returns
-------
viewables: list(Viewable)
"""
return super().select(selector) + self.layout.select(selector)

def get_root(self, doc=None, comm=None):
"""
Returns the root model and applies pre-processing hooks
Expand Down
18 changes: 18 additions & 0 deletions panel/tests/test_param.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,24 @@ class Test(param.Parameterized):
assert len(model.tabs) == 1


def test_param_js_callbacks(document, comm):
class JsButton(param.Parameterized):
param_btn = param.Action(lambda self: print('Action Python Response'), label='Action')

param_button = Param(JsButton())
code = "console.log('Action button clicked')"
param_button[1].js_on_click(code=code)

model = param_button.get_root(document, comm=comm)

button = model.children[1]
assert len(button.js_event_callbacks) == 1
callbacks = button.js_event_callbacks
assert 'button_click' in callbacks
assert len(callbacks['button_click']) == 1
assert code in callbacks['button_click'][0].code


class View(param.Parameterized):

a = param.Integer(default=0)
Expand Down