如何从React Redux表单中过滤传递给onSubmit方法的字段

时间:2019-02-12 05:56:06

标签: react-redux-form

return (
    <Form onSubmit={handleSubmit}>
      <DialogTitle>
        {title}
      </DialogTitle>

      <DialogContent>
        <section className={classes.section}>
          <h1
            className={!switchField ? classes.activeColor : classes.inactiveColor}>{intl.formatMessage(messages.regDate)}</h1>
          <Field
            component={Switch}
            name='switchField'
            color='default'
            status={switchField}
          />
          <h2
            className={switchField ? classes.activeColor : classes.inactiveColor}>{intl.formatMessage(messages.lastLoginDate)}</h2>
        </section>
        {!switchField ? <div className={classes.switch}>
          <SelectedDate name={intl.formatMessage(messages.regDate)} />
        </div> : null}
        {switchField ? <div className={classes.switch}>
          <SelectedDate name={intl.formatMessage(messages.lastLoginDate)} />
        </div> : null}
        <div className={classes.root}>
          <Field
            component={TextField}
            label={intl.formatMessage(messages.id)}
            name='_id'
            validate={length({ min: 24, allowBlank: true })}
            className={classes.fieldStyle}
            variant='outlined'
            normalize={normalization}
          />
          <Field
            component={TextField}
            label={intl.formatMessage(messages.firstName)}
            name='firstName'
            validate={length({ min: 2, allowBlank: true })}
            className={classes.fieldStyle}
            variant='outlined'
            normalize={normalization}
          />
          <Field
            component={TextField}
            label={intl.formatMessage(messages.lastName)}
            name='lastName'
            validate={length({ min: 2, allowBlank: true })}
            className={classes.fieldStyle}
            variant='outlined'
            normalize={normalization}
          />
        </div>
        <div className={classes.root}>
          <Field
            component={TextField}
            label={intl.formatMessage(messages.email)}
            name='email'
            className={classes.fieldStyle}
            variant='outlined'
            normalize={normalization}
          />
          <Field
            component={TextField}
            label={intl.formatMessage(messages.role)}
            name='role'
            validate={length({ min: 2, allowBlank: true })}
            className={classes.fieldStyle}
            variant='outlined'
            normalize={normalization}
          />
          <Field
            component={TextField}
            label={intl.formatMessage(messages.status)}
            name='status'
            validate={length({ min: 2, allowBlank: true })}
            className={classes.fieldStyle}
            variant='outlined'
            normalize={normalization}
          />
        </div>
      </DialogContent>

      <DialogActions>
        {actions(props)}
      </DialogActions>
    </Form>
  )

我有某种形式

export function getUsers (params) {
  return {
    types: [
      types.USERS_GET_REQUEST,
      types.USERS_GET_SUCCESS,
      types.USERS_GET_FAILURE
    ],
    payload: {
      request: {
        url: 'user',
        params
      }
    }
  }
}

我还有一些onSubmit函数

我的表单中有很多字段,但是要使用此字段将请求发送到服务器端,我将使用该字段作为参数params,例如,我不需要switchField。我如何从那里剪切它,但是在getUser函数之外呢?希望问题很清楚,如果不清楚请问我

0 个答案:

没有答案