3

I am trying to attach events in a select trought a function in a polymer element.

Till now, what I can do is something like that

html

<select on-change="changeData">
        <option>a</option>
..............

js

  changeData(dataset){
    console.log(dataset.target.value);
  }

and it's ok

however, when I want to call a function with inputs parameters I can't

html

<select on-change="changeData(event.target.value)">
        <option>a</option>
..............

js

  changeData(dataset){
    console.log(dataset);
  }

It doesn't work. Is anyone able to correct me or at least guide me on what I am doing wrong?

Thanks

ackuser
  • 5,681
  • 5
  • 40
  • 48
  • Yeah, you're registering event handlers in your HTML. Don't do that and you should be good. – Jared Smith Nov 29 '17 at 18:30
  • 1
    You can only specify a function name in `on-(event)` attributes. The function will always be called with an `event` type object. Give your ` – crazypeter Nov 29 '17 at 19:05
  • 1
    You're doing nothing wrong, the first version is the way to go. What don't you like about it? – mishu Nov 30 '17 at 11:52

1 Answers1

0

As @crazypeter said in the comments, you can't directly pass any arguments when adding event listeners, just the name of the function.

In this case you don't need to (the first example is correct), but if you would you can use data atributtes (see this question).

https://www.polymer-project.org/2.0/docs/devguide/events#annotated-listeners

Thomas Orlita
  • 1,554
  • 14
  • 28