javascript - submit dynamically created forms / React
问题描述
I'am developing a dApp using React, the contract has some data and I've created 5 (will be more) forms using map. I'm trying to figure out how to send them separately.
<div className="col-lg-12 row">
{this.props.documentos.map((documento, key) => {
return (
<form
key={key}
onSubmit={(event) => {
event.preventDefault();
const idDocumento = this.idDocumento;
const destinatario = this.txtAddressDestinatario.value;
const precio = this.txtPrecioAcordado.value;
console.log(idDocumento);
console.log(destinatario);
console.log(precio);
}}
>
<div className="card border-primary mb-3 mx-2">
<div
className="card-header bg-primary text-white"
ref={(this.idDocumento = documento.id)}
>
{documento.id} # {documento.nombre}
</div>
<div className="card-body text-primary">
<h5 className="card-title">
Precio realización trámite {documento.precio} ETH{" "}
</h5>
<p>
<input
id="txtAddressDestinatario"
type="text"
ref={(input) => {
this.txtAddressDestinatario = input;
}}
className="form-control"
placeholder="Dirección Destinatario"
required
/>
</p>
<p>
<input
id="txtPrecioAcordado"
type="text"
ref={(input) => {
this.txtPrecioAcordado = input;
}}
className="form-control"
placeholder="Monto"
required
/>
</p>
</div>
<div className="card-footer bg-transparent border-primary d-flex justify-content-center">
<button className="btn btn-warning mx-2">
Habilitar Documento
</button>
<button className="btn btn-primary mx-2" type="submit">
Generar Documento
</button>
</div>
</div>
</form>
);
})}
</div>;
What appears in the console is the id 5 and the values of the 5th Form (the last one). So it doesn't matter which form you are typing in, it just takes the values from the last one created.
I've been trying many ways to make it works. This is also my first "big" project using React. appreciate any advice.
Thanks
解决方案
推荐阅读
- c++ - 如何制作自定义字符串的 std::unorder_set 类型?
- java - 对于 repository.save(entityModel),Hibernate OneToMany 关联表字段不能为空
- haskell - 如何编写更短的代码,以便将其用于更广泛的目的?
- c++ - 带有 EnumDesktopWindows 的 printwindow 返回黑色图像
- python-3.x - groupby ,自定义函数每前 4 行使用一列(分组后)
- php - 如何“从 PHP 中的嵌套数组结构中获取数据”
- sql-server - 无法使用动态查询创建临时表
- r - ggplot2 3.2.0 版和bayesAB 绘图冲突
- sql - 在 Power BI 中的 Progress Open edge SQL 语句中组合日期字段和时间字段
- oracle-sqldeveloper - 如何显示来自 SQL Developer 的韩文字母