7

I have paper-input element

<paper-input 
    id="{{ id }}" 
    label="{{ label }}" 
    on-keyup="{{ keypressHandler }}" 
    value="{{ value }}">
</paper-input>

and I can catch event when key is released.

Polymer("app-input", {
    ready: function() {
        this.value = false;
    },
    keypressHandler: function(event, detail, sender) {
        console.log("inputChanged");
        console.log(this.value);
    }
});

But this.value is changed only when focus is removed from input field, so I'm not able to retrieve elements value at the moment button is released.

How can I get elements value in keypressHandler() ?

4

1 回答 1

9

对于paper-input(and core-input),inputValue是实时值,并且value是已提交值(当用户模糊字段或按 Enter 时更新)。

此外,考虑使用数据观察而不是事件。

<paper-input 
    id="{{ id }}" 
    label="{{ label }}" 
    inputValue="{{ value }}">
</paper-input>

...

Polymer("app-input", {
    valueChanged: function() {
        console.log("valueChanged");
        console.log(this.value);
    }
});
于 2014-06-29T18:16:15.463 回答