Polymer: get the value of paper-input inside a paper-dialog after paper-button press “ok”

浪子不回头ぞ 提交于 2019-12-11 02:59:34

问题


i need to get the value of some paper-input fields inside a paper-dialog after a press on a "ok" paper-button.

I have:

...
<paper-dialog id="notediag" heading="Add Note" transition="paper-dialog-transition-center">
    <paper-input id="dialog-add-note-header" label="Header"
        value="{{valHeader}}"></paper-input>
    <br>
    <paper-input id="dialog-add-note-text" label="Text"></paper-input>

    <paper-button label="Cancel" dismissive></paper-button>
    <paper-button label="Ok" affirmative default
        on-click="{{addNote}}"></paper-button>
</paper-dialog>
...

<script>
Polymer('note-list',{
  addNote: function(e, detail, sender)
  {
        var header=???
        console.log("add note "+header);
  }
});
</script>

I tried multiple ways to find the values of the paper-input fields but not found a propper way to do it. e.target.templateInstance does not work. A call to document.querySelector('#dialog-add-note-header') results in a null.

Any ideas?

Thanks for you help.

Stefan


回答1:


{{valHeader}} creates a property inside your note-list elelemt which is bound to the input value of the paper-input.

You can access it with

var header = this.valHeader

document.querySelector('#dialog-add-note-header') doesn't work, because the paper-input element is inside the shadow DOM of the paper-dialog. But you can use Polymer's node finding utility this.$.dialogAddNoteHeader (rename your id attribute to contain no dashes) to access the input element directly.



来源:https://stackoverflow.com/questions/24594947/polymer-get-the-value-of-paper-input-inside-a-paper-dialog-after-paper-button-p

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!