当我粘贴到该字段时,表单提交上的字段值为空

时间:2018-06-17 18:11:57

标签: redux redux-form

我需要在输入值(code)达到7个字符后发送表单。

如果我在输入(代码)中输入字符,它就可以了,表单会以适当的code值提交给服务器。

但是如果我在输入中粘贴了一些值,则请求中缺少code字段。

import React from 'react';
import { Field, reduxForm } from 'redux-form';
import { Link } from 'react-router-dom';
import { createTextMask } from 'redux-form-input-masks';
import PropTypes from 'prop-types';
import {connect} from 'react-redux';

const renderField = ({
  input,
  label,
  placeholder,
  type,
  className,
  meta: { touched, error, warning }
}) => (
  <div className="form-group ">
    <input {...input} placeholder={placeholder} type={type} className={'form-control ' + (touched && error ? 'is-invalid' : '')} />
    {touched &&
    ((error && <div className="invalid-feedback">{error}</div>) ||
      (warning && <span>{warning}</span>))}
  </div>
);

const checkCodeCompleted = (code, sbmt) => {
  if (code.length >= 7) {
    sbmt();
  }
};

let EmailConfirmationForm = props => {
  const { handleSubmit } = props;
  return (
    <form onSubmit={handleSubmit} className="needs-validation">    
      <Field name="code" component={renderField} type="text" className="form-control" placeholder="XXX-XXX" label="Confirmation code" onChange={(event, newValue) => { checkCodeCompleted(newValue, handleSubmit); } } />          
    </form>
  );
};


EmailConfirmationForm = reduxForm({
  form: 'emailConfirmationForm',
  enableReinitialize: true
})(EmailConfirmationForm);


export default EmailConfirmationForm;

问题是什么?

0 个答案:

没有答案