[英]Polymer iron-form, submitted twice on enter
Working on a comment element in Polymer, where the comment should be submitted when the user presses enter. 处理Polymer中的comment元素,当用户按下Enter时应在其中提交评论。 The enter part works, but the comment is getting submitted twice, causing a duplicate.
回车部分起作用,但是注释被提交了两次,从而导致重复。 Can you tell whats wrong?
你能说出什么问题吗? Thanks!
谢谢!
<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>
通过将setInterval添加到sendComment函数来解决此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.