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

js_on_click does not work for param.Action buttons #1327

Closed
sdc50 opened this issue May 7, 2020 · 1 comment · Fixed by #1439
Closed

js_on_click does not work for param.Action buttons #1327

sdc50 opened this issue May 7, 2020 · 1 comment · Fixed by #1439
Labels
type: bug Something isn't correct or isn't working
Milestone

Comments

@sdc50
Copy link
Contributor

sdc50 commented May 7, 2020

ALL software version info

In [3]: param.__version__                                                                                                                                                                                                                                                                                                                                               
Out[3]: '1.10.0a2'

In [4]: pn.__version__                                                                                                                                                                                                                                                                                                                                                  
Out[4]: '0.10.0a2'

Description of expected behavior and the observed behavior

Adding JavaScript code to a Button widget created from a param.Action through js_on_click doesn't have any effect.

Complete, minimal, self-contained example code that reproduces the issue

class JsButton(param.Parameterized):
    param_btn = param.Action(lambda self: print('Action Python Response'), label='Action')
    
    def panel(self):
        button_wg = pn.widgets.Button(name='Widget')
        button_wg.on_click(lambda e: print('Widget Python Response'))
        button_wg.js_on_click(code='console.log("Widget JS Response")')
        
        param_btn = pn.Param(self.param.param_btn)
        param_btn[0].js_on_click(code='console.log("Action JS Response")')
        
        return pn.Column(
            param_btn,
            button_wg,
        )
    
test = JsButton()
test.panel()

Stack traceback and/or browser JavaScript console output

Python callback returned following output:
	Action Python Response
Widget JS Response
Python callback returned following output:
	Widget Python Response
@xavArtley
Copy link
Collaborator

xavArtley commented May 7, 2020

As a work around you can do this

class JsButton(param.Parameterized):
    param_btn = param.Action(lambda self: print('Action Python Response'), label='Action')
    
    def panel(self):
        button_wg = pn.widgets.Button(name='Widget')
        button_wg.on_click(lambda e: print('Widget Python Response'))
        button_wg.js_on_click(code='console.log("Widget JS Response")')
        
        param_btn = pn.Param(self.param.param_btn)[0]
        param_btn.js_on_click(code='console.log("Action JS Response")')
        
        return pn.Column(
            param_btn,
            button_wg,
        )
    
test = JsButton()
test.panel()

@philippjfr philippjfr added the type: bug Something isn't correct or isn't working label May 19, 2020
@philippjfr philippjfr added this to the v0.9.6 milestone Jun 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't correct or isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants