Asking
Asking

Reputation: 4192

The value is not saved when submit form

I have a date picker where i set a default value.

const onFinish = values => {
  console.log("Received values of form: ", values);
};

ReactDOM.render(
  <Form name="validate_other" onFinish={onFinish} {...formItemLayout}>
    <Form.Item
      style={{
        display: "inline-block",
        width: "calc(50% - 12px)"
      }}
      name="picker"
    >
      <DatePicker
        value={moment().add(3, "days")}
        defaultValue={moment().add(3, "days")}
      />
    </Form.Item>

    <Form.Item wrapperCol={{ span: 12, offset: 6 }}>
      <Button type="primary" htmlType="submit">
        Submit
      </Button>
    </Form.Item>
  </Form>,

How you can see the default value is: defaultValue={moment().add(3, "days")}, thus is with 3 days after today.
Issue: When i click on Submit button i get undefined in console even i set the default date, but when change default value with a date from date picker, i get data.
Question: How to do next: when i will click on Submit button without choosing a date from calendar, to get the default value from date picker?

Upvotes: 0

Views: 90

Answers (1)

Anjali Chandwani
Anjali Chandwani

Reputation: 71

<Form.Item
  style={{
    display: "inline-block",
    width: "calc(50% - 12px)"
  }}
  name="picker"
  initialValue={moment().add(1, "days")}
>
  <DatePicker
  // value={moment().add(3, "days")}
  // defaultValue={moment().add(1, "days")}
  />
</Form.Item>

Upvotes: 0

Related Questions