[英]I can't access iron-form inside dom-repeat by using index
I'm loading some records from a cassandra database (using iron-ajax and dom-repeat) and by clicking on one row I'm opening a paper-dialog where values are loaded into an iron-form containing paper-input editable fields. 我正在从cassandra数据库中加载一些记录(使用iron-ajax和dom-repeat),然后单击一行,以打开一个纸张对话框,其中值被加载到包含纸张输入可编辑字段的铁表单中。 After editing I should be able to do submit in order to update the record in the database but using a paper-button it doesn't work (using a simple button at least is trying to send the content to the REST tough is ending with 415 error). 编辑后,我应该能够提交以便更新数据库中的记录,但是使用纸质按钮不起作用(至少使用一个简单的按钮正在尝试将内容发送到REST,以415结尾错误)。 What I tried is something like this: 我试过的是这样的:
<iron-ajax id="get_drafts" auto handle-as="json" last-response="{{drafts}}"></iron-ajax>
<template is="dom-repeat" items="{{drafts}}" as="item">
<div>{{item.field1}}</div>
<span><paper-button title="edit" on-click="openEditDialog"></paper-button></span>
<paper-dialog id="incidentEditDialog{{index}}" with-backdrop>
<form is="iron-form" action="/" id="myForm{{index}}" method="post">
<paper-input value="{{item.field1}}"><paper-input>
<paper-button raised on-click="submit">Submit</paper-button>
</form>
</paper-dialog>
</template>
and then tried with all kind of script options which didn't work I think mainly because I was not succeeded to identify the form by using the id - myForm{{index}} . 然后尝试使用所有无法使用的脚本选项,主要是因为我未能通过使用id-myForm {{index}}来成功识别表单。 I found all kind of examples but nothing with this twist (forms inside a dom-repeat). 我发现了各种示例,但都没有发现这种扭曲(在dom-repeat中形成)。 Is this something feasible at least? 这至少可行吗? How should I try doing it? 我应该如何尝试呢? thanks! 谢谢! If I use: 如果我使用:
<paper-button raised onclick="clickHandler(event)">Submit</paper-button>
and then the method 然后是方法
function clickHandler(event) {
Polymer.dom(event).localTarget.parentElement.submit();
}
I get the 415 error: There was an unexpected error (type=Unsupported Media Type, status=415). 我收到415错误:发生意外错误(类型=不支持的媒体类型,状态= 415)。 Content type 'application/x-www-form-urlencoded' not supported 不支持内容类型“应用程序/ x-www-form-urlencoded”
The problem is that <form>
(even extended with the iron-form) will not work together as seamlessly with paper-button as it does with a native <button>
or <input>
. 问题是<form>
(甚至用铁表单扩展)在纸质按钮上无法像在本机<button>
或<input>
那样无缝地协同工作。
When you do on-click="submit"
on paper-button, you will need to define a submit
method (the same way as you do with the clickHandler in your example). 当你on-click="submit"
纸上按钮,您将需要定义一个submit
方法(相同的方式,你在你的例子对clickHandler做)。
If you don't want to do that, a good workaround is to wrap the paper-button in a native button: 如果您不想这样做,一个好的解决方法是将纸质按钮包装在本机按钮中:
<button tabindex="-1"> <paper-button>Submit</paper-button> </button>
The negative tabindex is there so the wrapper can't get focus. tabindex为负,因此包装器无法获得焦点。
The Unsupported Media Type error is a separate issue, but adding content-type="application/json"
to your <form>
might help there. 不受支持的媒体类型错误是一个单独的问题,但是将content-type="application/json"
到<form>
可能会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.