import React, { Component } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { mapDispatchToProps } from 'client/utils/redux';
import { InputTextField } from './input';
import { Label } from './label';
@connect(
(state) => ({
deliveryFormData : state.api.commerce.deliveryFormData
}),
mapDispatchToProps(['commerce'])
)
export class DynamicForm extends Component {
constructor(props) {
super(props);
this.load();
this.state = {};
}
load = (ev) => {
ev && ev.preventDefault();
this.props.actions.commerce.getDeliveryFormData();
}
_handleChange = event => {
}
handleFormSubmit(e) {
e.preventDefault();
let form = document.forms.namedItem("delivery-form")
let userData = new FormData(form)
console.log(e.target[0].value)
fetch("http://nbrstage2.folz.de/api/v1/shipping/submit_form", {
method: "POST",
body: JSON.stringify(userData),
headers: {
Accept: "application/json",
"Content-Type": "application/json"
}
}).then(response => {
response.json().then(data => {
console.log("Successful" + data.errors);
});
});
}
submitForm = event => {
event.preventDefault();
// const formData = new FormData(event);
console.log(this.formData.fields);
this.formData.fields.map(e => {
console.log(e.label);
})
}
get formData() {
return this.props.deliveryFormData.payload.form;
}
render() {
console.log(Object.entries(this.formData))
return (
<form name="delivery-form" type="post" action="/api/v1/shipping/submit_form" onSubmit={this.handleFormSubmit}>
{
this.formData.fields.map(e => console.log(e.label))
}
</form>
)
}
}
поэтому с allElements нужно работать в цикле
Ссылка на документацию по NodeList