modal and form validation no destory
See original GitHub issueVersion
3.0.0
Environment
mac
Reproduction link
https://user-images.githubusercontent.com/26153901/34207207-75573d12-e5c4-11e7-9a0e-af7932d58aec.gif
Steps to reproduce
According to the official website example add modal
repat
1.invoke add function 2.invoke remove function 3.invoke open function 4.input value 5.invoke modal ok function
gif
code
import React, { Component } from 'react';
import { Button, Form, Icon, Input, Modal } from 'antd';
@Form.create()
export default class Home extends React.Component {
state={
modalVisible: false,
}
open=() => {
this.setState({ modalVisible: true });
}
cancel=() => {
this.setState({ modalVisible: false });
}
ok=() => {
this.props.form.validateFields((errors) => {
if (errors) {
console.log('no pass');
return;
}
console.log('pass');
});
}
remove = () => {
const { form } = this.props;
form.setFieldsValue({
keys: [1],
});
console.log('remove two input');
}
add = () => {
const { form } = this.props;
form.setFieldsValue({
keys: [1, 2, 3],
});
console.log('load three input');
}
render() {
const { getFieldDecorator, getFieldValue } = this.props.form;
const { modalVisible } = this.state;
getFieldDecorator('keys', { initialValue: [] });
const keys = getFieldValue('keys');
const formItems = keys.map((k) => {
return (
<Form.Item required={false} key={k} >
{getFieldDecorator(`names[${k}]`, {
rules: [{
required: true,
message: "Please input passenger's name or delete this field.",
}],
})(
<Input placeholder="passenger name" />
)}
</Form.Item>
);
});
const modalProps = {
visible: modalVisible,
onOk: this.ok,
onCancel: this.cancel,
};
return (
<div>
<Modal {...modalProps}> {
<Form layout="horizontal">
{formItems}
</Form>
}
</Modal>
<Button type="dashed" onClick={this.add}>
<Icon type="plus" /> add3
</Button>
<Button type="dashed" onClick={this.remove}>
<Icon type="plus" /> remove2
</Button>
<Button type="dashed" onClick={this.open}>
<Icon type="plus" /> show
</Button>
</div>
);
}
}
What is expected?
invoke modal ok function after,The first input box and the second input box should be destroyed
What is actually happening?
The first input box and the second input box are not destroyed,It causes validation not to pass
How do I destroy the components that I created before?
Issue Analytics
- State:
- Created 6 years ago
- Comments:13 (5 by maintainers)
Top Results From Across the Web
How do I validate form elements in a modal without closing?
To add custom validation to this form's elements ('live' validation that does not close the modal). I recognize that this type of problem...
Read more >FormValidation on modal bootstrap - Stack Overflow
When btnAddMovie is clicked I ajax / jquery method is called which calls a method in my controller. But before I submit I...
Read more >HTML5 Form Validation and Bootstrap Modal Dialogue not ...
I have a very simple form with one field of type numeric. I have the forms submit button linked to a Bootstrap modal...
Read more >Modal · Bootstrap v5.0
Use Bootstrap's JavaScript modal plugin to add dialogs to your site for lightboxes, user notifications, or completely custom content.
Read more >How to build modals with Hotwire (Turbo Frames + StimulusJS)
At Bearer.com we use a lot of modals. They allow our users to create/edit/destroy records throughout the app, without leaving the current ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Try
destroyOnClose
Please provide more details and use cases.