Reputation: 815
I'm using ant design for my react project.
In this, I need to add dynamic select and get values. Now I can able to select dropdown dynamically.
But I'm not able to get values.
handleSubmit = e => {
e.preventDefault();
this.props.form.validateFields((err, values) => {
if (!err) {
alert("Received values of form: ", values);
}
});
};
Demo: https://codesandbox.io/s/nrxq1505v0
Upvotes: 2
Views: 509
Reputation: 1896
This will resolve your problem.
this.props.form.validateFields((err, values) => {
e.preventDefault();
if (!err) {
alert("Received values of form: " + values.names.join());
}
});
Upvotes: 2
Reputation: 3773
Please check all time your variable assign correct variable type or your expected variable using
console.log('comment', variable);
this is easy way, or you can debug your code
Please check working example link.
Upvotes: 0
Reputation: 34004
You need to do like below to get values
this.props.form.validateFields((err, values) => {
const data = JSON.stringify(values);
const d = JSON.parse(data);
console.log("d...", d.names)//this gives values in an array. It prints like this ["lucy", "jack"] when I added two fields and seleted value from each field
if (!err) {
alert("Received values of form: ", d.names);
}
});
Upvotes: 0