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

button value binding does not work if button has nested elements #2497

Closed
miyconst opened this issue Sep 30, 2015 · 12 comments
Closed

button value binding does not work if button has nested elements #2497

miyconst opened this issue Sep 30, 2015 · 12 comments

Comments

@miyconst
Copy link

On my page I have a button:

<button onclick="++this.value" value="{{model.value::click}}">++</button>

The purpose of the button is to increase model.value by one and notify Polymer about the change. The code above works fine, but this one does not work:

<button onclick="++this.value" value="{{model.value::click}}">
    <i>{{model.value}}</i>
    <span>++</span>
</button>

If button has any nested elements, then model.value became undefined on click. Here is a jsfiddle which demonstrates the issue: https://jsfiddle.net/z1knafu5/.

@dfreedm
Copy link
Member

dfreedm commented Nov 7, 2015

I'd suggest not using onclick here. I'm not 100% sure what part of the data binding system is unhappy with your solution, but here is a nearly-identical working example that uses the data-binding APIs
https://jsfiddle.net/thaL2515/

@miyconst
Copy link
Author

miyconst commented Nov 7, 2015

@azakus,

I know that JavaScript function instead of inline event handler works correct, but in our system we use integer properties to trigger button click on server side.

It is really annoying to add click function for each button to just increment a value.

@zoechi
Copy link

zoechi commented Nov 7, 2015

Why don't you create a fancy-button that does that and reuse it everywhere?

@miyconst
Copy link
Author

miyconst commented Nov 7, 2015

Well, I did something like this, but the exception with binding is still there and should be fixed.

@jwillmer
Copy link

jwillmer commented Feb 4, 2016

This is really annoying and it took me again half a day of debugging to find the problem. Could someone fix this? It can’t be to complicated.

@diliger
Copy link

diliger commented Feb 8, 2016

+1

@warpech
Copy link

warpech commented Feb 11, 2016

+1. Just spend 2 hours debugging this case :(

@tomalec
Copy link
Contributor

tomalec commented Feb 11, 2016

I suspect it's something related to event delegation/ event target handling, as existence of nested element does not break a thing, but clicking on the element inside which may not be bound to anything breaks it:
https://jsfiddle.net/tomalec/6w7tu42h/1/

@jfrazzano
Copy link

Organically a button's value is the buttons name. You can use other props or reset value.

I have a universal input which does everything from buttons, toggles, papering icon buttons, check boxes radio groups native selects with items entered as atts or nested dom repeats.

For buttons I find using a section or span or similar to wrap an icon is easiest And allows for a button set based on CSS classes which I assign at Dom repeat instance no via input type tied classes and secondary classes in another on top prop.

The button value like the radio ad check box value are just not "value tied" natively so a secondary prop is the usual method. If you monkey with it you could more or less do anything.

It's up to you really

Sent from my iPhone

On Feb 11, 2016, at 1:11 PM, Tomek Wytrębowicz [email protected] wrote:

I suspect it's something related to event delegation/ event target handling, as existence of nested element does not break a thing, but clicking on the element inside which may not be bound to anything breaks it:
https://jsfiddle.net/tomalec/6w7tu42h/1/


Reply to this email directly or view it on GitHub.

@aloscha
Copy link

aloscha commented Apr 22, 2016

+1

@tjsavage tjsavage added the 1.x label Sep 8, 2016
@Mackiovello
Copy link

+1 extremely annoying bug

@TimvdLippe
Copy link
Contributor

This issue has been addressed in #5308 and will be fixed in 2.x and 3.x. Therefore I am closing this issue, as it targets 1.x. Please update your version of Polymer once we have released the fixes.

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

No branches or pull requests