0
處理Polymer中的註釋元素,其中當用戶按下Enter時應提交註釋。輸入部分工作,但評論提交兩次,導致重複。你能說出什麼是錯的嗎?謝謝!聚合物鐵形式,在輸入時提交兩次
<link rel="import" href="/bower_components/polymer/polymer.html">
<link rel="import" href="/bower_components/paper-input/paper-input.html">
<link rel="import" href="/bower_components/iron-form/iron-form.html">
<link rel="import" href="/bower_components/iron-input/iron-input.html">
<link rel="import" href="/bower_components/iron-a11y-keys/iron-a11y-keys.html">
<dom-module is="post-comments">
<template>
<div class="wrapper">
<div class="comment-input-wrapper">
<iron-a11y-keys id="a11y" keys="enter" target="[[target]]"
on-keys-pressed="sendComment" stopKeyboardEventPropagation="true"></iron-a11y-keys>
<form is="iron-form" method="get" action="/ajax/group/comment.php" id="commentForm">
<input is="iron-input" type="text" name="comment" placeholder="Kommenter..." value="{{commentInput::input}}" class="comment_input" id="currentComment">
<input type="hidden" name="post_id" value="{{postId}}">
</form>
</div>
</div>
</template>
<script>
Polymer({
is: "post-comments",
properties: {
postId: {
type: Number
},
commentInput: {
type: String,
notify: true
},
target: {
type: Object,
value: function() {
return this.$.currentComment;
}
}
},
listeners: {
'iron-form-response': 'displayMessage'
},
sendComment: function(e) {
this.$.commentForm.submit();
},
displayMessage: function(e) {
//Display response
}
});
</script>
</dom-module>