googlearchive / paper-slider

A slider à la Material Design
16 stars 18 forks source link

Data binding to immediateValue #38

Open kforeman opened 9 years ago

kforeman commented 9 years ago

I'd like an element which updates to show the immediateValue of the slider. So I try binding like so:

<paper-slider snaps step="1" immediateValue="{{x}}"></paper-slider>
<div id='slider-label'>{{x}}</div>

However, even though I'm using immediateValue it only updates after the drag event has concluded (i.e. it's working just like value does).

My work around has been to use the following javascript instead:

<paper-slider snaps step="1"></paper-slider>
<div id='slider-title'></div>
<script>
    document.querySelector('paper-slider').addEventListener('immediate-value-change', function(e) {
        document.querySelector('#slider-label').textContent = this.immediateValue;
    });
</script>

That works. But shouldn't the Polymer binding approach work as well?

frankiefu commented 9 years ago

It seems to work fine for me. See this jsbin: http://jsbin.com/jocuzeyuzu/1/edit

kforeman commented 9 years ago

Hmm, that minimal example is working for me as well. But when I copy that code into my larger project it breaks - will try to track down where the conflict arises. Thanks!

teamoWeekend commented 8 years ago

Did you eventually fix it? If so: What was the cause? I have the very same problem. Looking deeper in it I find, that if I extend the paper-slider observer for immediateValue and change from this:

_immediateValueChanged: function() {
      if (this.dragging) {
        this.fire('immediate-value-change');
      } else {
        this.value = this.immediateValue;
      }
    },

to that:

_immediateValueChanged: function() {
      if (this.dragging) {
        this.fire('immediate-value-change');
        this.value = this.immediateValue;
      } else {
        this.value = this.immediateValue;
      }
    },

and I add a data-binding to the value instead in the index.html it at least updates the value in the div. If I stick to immediateValue it doesn't even show a 0 at the beginning. It is just empty all the time.

purpledog commented 8 years ago

Same problem here, any updates?

My work around was to bind to "value" and add listeners on "immediate-value-change".