question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

modal and form validation no destory

See original GitHub issue

Version

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

address

repat

1.invoke add function 2.invoke remove function 3.invoke open function 4.input value 5.invoke modal ok function

gif

image

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:closed
  • Created 6 years ago
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
afc163commented, Jul 13, 2018

Try destroyOnClose

0reactions
benjycuicommented, Dec 22, 2017

Can you provide an active destroy all form method?

Please provide more details and use cases.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found