2017-09-05 95 views
0

您好我已經得到了我的代碼2個問題:Reactjs- comboDatePicker驗證和恢復狀態

  1. 我有有類似名稱的公共領域,用戶詳細信息的表格。我在表單中添加了出生日期字段。爲此,使用comboDatePicker。問題是,當我提交表格並返回表單上的正確詳細信息時,除出生日期外,所有字段均保持完好。它回到默認值。

  2. 什麼是使此出生日期爲強制性的最簡單方法。

下面是我的代碼:

<Row> 
    <Col sm={6} md={12}> 
     <FormGroup> 
      <Col md={3} mdOffset={1}> 
       <ControlLabel>Date Of Birth</ControlLabel> 
      </Col> 
      <Col md={6}> 
       <ComboDatePicker 
        placeholder="Year,Month,Date" 
        id="dateOfBirth" 
        ref={e => refs.dateOfBirth = e} 
        onValueUpdated={preSaveFormState}                     
     attrsYear={{className:"form-control pull-left", style: {width: "auto"}}} 
     attrsMonth={{className:"form-control pull-left", style: {width: "auto"}}} 
     attrsDate={{className:"form-control pull-left", style: {width: "auto"}}} 
       /> 
      </Col> 
     </FormGroup> 
    </Col> 
</Row> 

回答

0

您可以設置date道具爲ComboDatePicker組件。

<Row> 
    <Col sm={6} md={12}> 
     <FormGroup> 
      <Col md={3} mdOffset={1}> 
       <ControlLabel>Date Of Birth</ControlLabel> 
      </Col> 
      <Col md={6}> 
       <ComboDatePicker 
        placeholder="Year,Month,Date" 
        date={this.state.date} // you can set and read the date from state 
        id="dateOfBirth" 
        ref={e => refs.dateOfBirth = e} 
        onValueUpdated={preSaveFormState}                     
     attrsYear={{className:"form-control pull-left", style: {width: "auto"}}} 
     attrsMonth={{className:"form-control pull-left", style: {width: "auto"}}} 
     attrsDate={{className:"form-control pull-left", style: {width: "auto"}}} 
       /> 
      </Col> 
     </FormGroup> 
    </Col> 
</Row>