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

ReactiveHTML element not working on elements without and id #2684

Closed
MarcSkovMadsen opened this issue Aug 28, 2021 · 3 comments
Closed

ReactiveHTML element not working on elements without and id #2684

MarcSkovMadsen opened this issue Aug 28, 2021 · 3 comments
Labels
type: docs Related to the Panel documentation and examples
Milestone

Comments

@MarcSkovMadsen
Copy link
Collaborator

MarcSkovMadsen commented Aug 28, 2021

I'm on Panel 0.12.1 exploring the ReactiveHTML.

Not Working - No id on img

Nothing happens when I click

from panel.reactive import ReactiveHTML
import param

class Slideshow(ReactiveHTML):

    index = param.Integer(default=0)

    _template = '<img src="https://picsum.photos/800/300?image=${index}" onclick="${_callback}"></img>'

    def _callback(self, event):
        self.index += 1

Slideshow(width=800, height=300).servable()

Working

If I change the _template to

_template = '<img id="img" src="https://picsum.photos/800/300?image=${index}" onclick="${_callback}"></img>'

Additional Context

Its confusing that the 1) The id is required and this requirement is not mentioned in the guide https://panel.holoviz.org/user_guide/Custom_Components.html#reactivehtml-components and 2) The in the guide the id is called input and the onclick method is called _input_click. The relation in the example between the name of the input and the name of the callback makes it hard to figure out what is required and what is not.

I can now see that 1) the id is required 2) the callback can have any name.

@MarcSkovMadsen MarcSkovMadsen added TRIAGE Default label for untriaged issues type: docs Related to the Panel documentation and examples and removed TRIAGE Default label for untriaged issues labels Aug 28, 2021
@philippjfr philippjfr added this to the 0.12.2 milestone Aug 29, 2021
@philippjfr
Copy link
Member

I think we can also improve validation here, raising errors when trying to attach callbacks to DOM nodes without an ID.

@philippjfr
Copy link
Member

philippjfr commented Aug 30, 2021

How's this as an error:

ValueError: DOM nodes with an attached callback must declare an id. Found node with onclick callback referencing _callback method. Add an id attribute like this: <img id="img" onclick="${_callback}>...</img>.

@philippjfr
Copy link
Member

philippjfr commented Aug 30, 2021

Also going to be stricter about linked parameters (${parameter}) vs. literals ({{ parameter }}):

ValueError: DOM node with a linked parameter declaration must declare an id. Found node with the src attribute referencing the index parameter. Either declare an id on the node, i.e. <img id="img" src="https://picsum.photos/800/300?image=${index}">...</img>, or insert the value as a literal: <img src="https://picsum.photos/800/300?image={{index}}">...</img>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: docs Related to the Panel documentation and examples
Projects
None yet
Development

No branches or pull requests

2 participants