2017-06-02 105 views
1

我使用的是組件的加載形式,我從api響應中獲得我的文本字段的值,當我填充並提交這些值時,因爲我沒有觸及域 - 我我看到驗證錯誤 - 就像它們是空的 - 如何將這些現有值傳遞給道具?Redux窗體預先填充的數據

const emailValfromapi = this.props.data && this.props.data.email ? this.props.data.email : []; 
    const { handleSubmit, fields: { email, abc, def, etc } } = this.props; 
      <fieldset className="form-group"> 
          <div className="input-wrapper"> 
          <input value={emailValfromapi} id="email" {...email} type="email" className={email.touched && email.error ? 'error-red' : ''} required /> 
          <label className="input-label" htmlFor="Email">To</label> 
          { email.touched && email.error && <div className="alert-danger"> { email.error } </div> } 
          </div> 
         </fieldset> 

回答

1

redux-form你不爲自己輸入的值傳遞,而是使用the Field component包投入,讓庫處理數據綁定。在這種情況下,輸入是填充的,但redux-form不知道它的存在,因爲它沒有包含在Field組件中。這個例子給你一個關於Field組件的基本用法的簡要說明。

此外,要將初始值傳遞給表單組件,您需要使用initialValues prop(最好由this example描述)。

希望這會有所幫助!