question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DatePicker can not load date

See original GitHub issue

Version

2.7.4

Environment

win7 chrome

Reproduction link

http:none

Steps to reproduce

import React , { Component } from 'react';
import { Form , Icon , Input , Button , DatePicker } from 'antd';
import moment from 'moment';

const FormItem = Form.Item;


class Test extends Component {

    componentDidMount(){
        const { setFieldValue , setFieldsValue } = this.props.form;
        // can not load this date
        setFieldsValue({username:'admin',password:'abcde',date:1491462025480})
    }

    handleSubmit = (e)=>{
        e.preventDefault();
        this.props.form.validateFields((e,value)=>{
            if(e)return;
            console.info('value=>',value)
        })
    }
    render(){
        const { getFieldDecorator } = this.props.form;
        return (
            <div>
                <Form layout="horizontal" onSubmit={::this.handleSubmit}>
                    <FormItem>
                        {getFieldDecorator('date',{
                            rules:[{required:true}]
                        })(
                            <DatePicker format={`YYYY-MM-DD HH:mm:ss`}  />
                        )}
                    </FormItem>
                    <Button htmlType="submit" type="primary">submit</Button>
                </Form>
            </div>
        )
    }
}


export default Form.create({})(Test);

What is expected?

load date correctly

What is actually happening?

can not load date


antd@2.8.3 errMsg => inputValue.format is not a function

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
infengcommented, Apr 6, 2017

try this:

...
 componentDidMount(){
   const { setFieldValue , setFieldsValue } = this.props.form;
   // can not load this date
   setFieldsValue({username:'admin',password:'abcde'date: moment(1491462025480)})
}
...
1reaction
infengcommented, Apr 6, 2017

value of DatePicker only support type moment. https://ant.design/components/date-picker/#DatePicker

Read more comments on GitHub >

github_iconTop Results From Across the Web

jquery - Datepicker won't load Properly - Stack Overflow
Hi I'm working with project, I have a problem with bootstrap datepicker it's not displaying properly, I don ...
Read more >
<input type="date"> - HTML: HyperText Markup Language
Even though the date picker doesn't use it, the text input fallback will. For example, try viewing the following in an unsupporting browser:....
Read more >
Solved: Date is not appearing as date field in datepicker
i want to use the datepicker, but nothing is appearing as datefield. start and endate are saved like this in the database: 2021-07-13...
Read more >
Date Picker Dialog Example | APG | WAI - W3C
When the dialog is opened, if the input field is empty, or does not contain a valid date, then the current date is...
Read more >
Datepicker Widget - jQuery UI API Documentation
The jQuery UI Datepicker is a highly configurable plugin that adds datepicker functionality to your pages. You can customize the date format and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found