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

onchange listener can't be on any element other than input textare or select #1776

Closed
1 of 3 tasks
Tracked by #1666
ranile opened this issue Mar 2, 2021 · 1 comment · Fixed by #2000
Closed
1 of 3 tasks
Tracked by #1666

onchange listener can't be on any element other than input textare or select #1776

ranile opened this issue Mar 2, 2021 · 1 comment · Fixed by #2000
Labels

Comments

@ranile
Copy link
Member

ranile commented Mar 2, 2021

Tracking issue for the point, " Inability to listen to change event" described in #1666

Problem

Passing onchange where its not allowed results in a panic: panicked at 'only an InputElement, TextAreaElement or SelectElement can have an onchange event listener'. This should be allowed.

from #1666

Steps To Reproduce

  1. Use onchange listener on any element other than input textare or select
  2. Notice how it panics: panicked at 'only an InputElement, TextAreaElement or SelectElement can have an onchange event listener

Expected behavior
It should attach listener instead of panicing

Environment:

  • Yew version: master
  • Rust version: irrelevant (don't exactly remember which one I used when I encountered this)
  • Target, if relevant: wasm32-unknown-unknown (irrelevant here)
  • Build tool, if relevant: trunk (irrelevant here)
  • OS, if relevant: Arch Linux (irrelevant here)
  • Browser and version, if relevant: Firefox (irrelevant here)

Questionnaire

  • I'm interested in fixing this myself but don't know where to start
  • I would like to fix and I have a solution
  • I don't have time to fix this right now, but maybe later

I apologize it took me so long to create this issue after being requested here (#1666 (comment))

@ranile ranile added the bug label Mar 2, 2021
@ranile ranile changed the title type attribute can only be used with input and button elements onchange listener can't be on any element other than input textare or select Mar 2, 2021
@mc1098
Copy link
Contributor

mc1098 commented Aug 1, 2021

Instead of ChangeData I was thinking we could just wrap the web_sys::Event in a new type ChangeEvent - this could have helper functions impl on it to cover what the ChangeData variants. These helper functions should use the event in order to get the value or FileList as this allows onchange callbacks to be added to wrapper elements and catch bubbling change events.

Also we could actually get value from select elements, in the respective helper function, which would get the value of the first option element that is selected.

ChangeEvent would follow the same style as web_sys and deref web_sys::Event so that users who were catching change events from custom elements or custom logic could still use the web_sys::Event to perform whatever logic required.

Curious what you think of this idea? I'm wondering whether defining a type that seems and acts like a web_sys type is good, or confusing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants