values.get不是redux格式验证函数中的函数

时间:2017-11-03 12:14:35

标签: reactjs validation redux redux-form

我第一次面对一个非常奇怪的问题。我有一个容器,通过它我可以将组件连接到redux表单。我的代码在这里:

import { connect } from 'react-redux';
import { reduxForm } from 'redux-form/immutable';
import PayrollSearch from './payrollSearch';
import { requestPayrollInfo } from '../../actions/payrollActions';
import { PAYROLL_SEARCH } from '../../common/constants';

export const validate = (values) => {
  const errors = {};
  const onlyNumbers = /^([0-9])+$/g;
  if (!values.get('processId')) {
    if (onlyNumbers.test(values.get('processId'))) {
      errors.processId =
        'Ο μοναδικός αριθμός αρχείου πρέπει να περιέχει μόνο αριθμούς';
    }
  }
  return errors;
};

export const mapDispatchToProps = dispatch => (
  {
    onSubmit: formData =>
      dispatch(requestPayrollInfo(formData))
  }
);

const PayrollSearchForm = reduxForm({
  form: PAYROLL_SEARCH,  // a unique identifier for this form
  validate
  initialValues: {
    from: new Date(),
    to: new Date()
  }
})(PayrollSearch);

const PayrollSearchContainer = connect(
  null,
  mapDispatchToProps
)(PayrollSearchForm);

export default PayrollSearchContainer;

PayrollSearch代码在这里:

import React, { PropTypes } from 'react';
import { Field } from 'redux-form/immutable';
import moment from 'moment';
import MenuItem from 'material-ui/MenuItem';
import {
  SelectField,
  DatePicker
} from 'redux-form-material-ui';
import RaisedButton from 'material-ui/RaisedButton';
import inputTextField from '../../../widgets/inputTextField/index';


const PayrollSearch = props => (
  <form onSubmit={props.handleSubmit}>
    <div>
      <Field
        name={DATE_FROM_FIELD}
        component={DatePicker}
        floatingLabelText={PAYROLL_DATE_FROM}
        autoOk
        formatDate={date => moment(date).format('DD-MM-YYYY')}
      />
      <Field
        name={DATE_TO_FIELD}
        component={DatePicker}
        floatingLabelText={PAYROLL_DATE_TO}
        autoOk
        formatDate={date => moment(date).format('DD-MM-YYYY')}
      />
    </div>
    <div>
      <Field
        name={PROCESSID_FIELD}
        component={inputTextField}
        floatingLabelText={PAYROLL_PROCESS_ID}
        style={styles.f1}
      />
      <Field
        name={FILENAME_FIELD}
        component={inputTextField}
        floatingLabelText={PAYROLL_FILENAME}
        style={styles.f1}
      /><br /><br />
      <Field
        name={STATUS_FIELD}
        component={SelectField}
        hintText={PAYROLL_STATUS}
      >
        <MenuItem value="all" primaryText="'Ολα" />
        <MenuItem value={3} primaryText="Εκκρεμεί επιβεβαίωση" />
        <MenuItem value={954} primaryText="Μη εκτελέσιμο" />
        <MenuItem value={998} primaryText="Μερικώς εκτελεσμένο" />
      </Field>
      <Field
        name={KEYWORD_FIELD}
        component={inputTextField}
        floatingLabelText={PAYROLL_KEYWORD}
        style={styles.f1}
      />
    </div><br /><br />
    <div>
      <RaisedButton
        onClick={() => props.reset()}
        label="Clear search"
        style={styles.f2}
      />
      <RaisedButton
        type="submit"
        primary
        label={PAYROLL_SEARCH_BUTTON}
      />
    </div>
  </form>
);

PayrollSearch.propTypes = {
  handleSubmit: PropTypes.func,
  reset: PropTypes.func
};

export default PayrollSearch;

当渲染PayrollSearcComponent时,出现错误,表示values.get不是函数。这到底为什么会发生这种情况?这是我以前没见过的问题

0 个答案:

没有答案