编辑表格的问题

时间:2018-12-06 08:20:17

标签: reactjs

我对提交修改后的表格有疑问。当我尝试单击“提交”按钮时,该表单没有关闭。这是代码

 constructor(props) {
    super(props);

    this.state = {
      initial: true,
    };

    this.handleCloseModal = this.handleCloseModal.bind(this);
    this.handleFormSubmit = this.handleFormSubmit.bind(this);
  }

  componentWillReceiveProps(newProps) {
        const { change, calendarEvent } = this.props;
        if (newProps.calendarEvent !== calendarEvent) {
          if (newProps.calendarEvent && newProps.calendarEvent.summary) {
            change('title', newProps.calendarEvent.summary);
          }

          if (newProps.calendarEvent && newProps.calendarEvent.description) {
            change('description', newProps.calendarEvent.description);
          }

          if (newProps.calendarEvent && newProps.calendarEvent.start.dateTime) {
            const hours = moment(newProps.calendarEvent.start.dateTime).format('hh');
            change('hour', parseInt(hours));
            const minutes = moment(newProps.calendarEvent.start.dateTime).format('mm');
            change('minute', parseInt(minutes));
            const period = moment(newProps.calendarEvent.start.dateTime).format('A');
            change('period', period);
          }
        }
      }

      handleCloseModal() {
        this.props.resetForm();
        this.props.onHide(false);
      }

      handleFormSubmit(event) {
        event.preventDefault();
        const { formError, formValues, onSubmit, calendarEvent, touchFields } = this.props;

        if (!formValues.title || !formValues.period || !formValues.hour || !formValues.minute) {
          touchFields();
        } else if (!formError) {
          onSubmit({ event: calendarEvent, formValues });
        }
      }

以某种方式,handleFormSubmit方法不起作用。什么不对?

1 个答案:

答案 0 :(得分:0)

在onSumbit调用之后,尝试调用this.handleCloseModal();