a.com
January 3, 2017, 1:21pm
1
I’m trying to use AntD with a datepicker form but keep getting this error:
Uncaught TypeError: config._d.getTime is not a function
at new Moment (modules.js?hash=08b0bfb…:67890)
at Moment.clone (modules.js?hash=08b0bfb…:70654)
at Moment.toISOString (modules.js?hash=08b0bfb…:70779)
at Moment.toJSON (modules.js?hash=08b0bfb…:70974)
at JSON.stringify (<anonymous>)
at Object.DDPCommon.stringifyDDP (ddp-common.js?hash=1414c62…:243)
at Connection._send (ddp-client.js?hash=bc32a16…:4152)
at MethodInvoker.sendMessage (ddp-client.js?hash=bc32a16…:3548)
at Connection.apply (ddp-client.js?hash=bc32a16…:4076)
at Connection.call (ddp-client.js?hash=bc32a16…:3840)
Here is my psudo code:
import React from 'react';
import { Link } from 'react-router';
import { StyleSheet, css } from 'aphrodite'
import { DashboardContainer, FormCard } from '../../common'
import { Form, Icon, Input, Card, Button, Checkbox, Row, Select, DatePicker } from 'antd';
const FormItem = Form.Item;
const Option = Select.Option;
const AddEventForm = Form.create()(React.createClass({
getInitialState () {
return {
loading: false
};
},
handleSubmit(e) {
e.preventDefault();
let data = { };
this.props.form.validateFields((error, values) => {
let { resourceType, stages, title, description, tags, location, date, clusters } = values
data = { resourceType, stages, title, description, tags, location, date, clusters };
Meteor.call('Events.addEvent', data, function(){
if (error) { failure(error); return; }
});
});
},
render() {
return (
<Form onSubmit={this.handleSubmit} className="login-form">
<FormItem>
{getFieldDecorator('date', {
rules: [{ required: true, message: 'Please input your location!' }],
})(
<DatePicker addonBefore={<Icon type="calendar" />} placeholder="event date" />
)}
</FormItem>
<Button type="primary" htmlType="submit">
Add Event
</Button>
</FormItem>
</Form>
);
},
}));
export const Events = ( ) => (
<DashboardContainer pageTitle={'Resource Events'}>
<FormCard>
<AddEventForm />
</FormCard>
</DashboardContainer>
);
related links:
https://github.com/lb-/moment-helpers/issues/38
opened 05:09AM - 10 Oct 15 UTC
closed 05:27AM - 10 Oct 15 UTC
I keep getting errors:
```
momentjs_moment.js:186 Uncaught TypeError: config._d… .getTime is not a function
Moment @ momentjs_moment.js:186
clone @ momentjs_moment.js:1848
newMomentProto.clone @ rzymek_fullcalendar.js:926
moment_format__toISOString @ momentjs_moment.js:1944
EJSON.stringify @ ejson.js:343
stringify @ reactive-dict.js:6
_.extend.set @ reactive-dict.js:61
Template.events.helpers.options.eventClick @ visits.js:40
trigger @ rzymek_fullcalendar.js:8308
fc.View.Class.extend.trigger @ rzymek_fullcalendar.js:6635
Grid.mixin.bindSegHandlers.$.each.click @ rzymek_fullcalendar.js:3647
(anonymous function) @ rzymek_fullcalendar.js:3665
jQuery.event.dispatch @ jquery.js:4665
jQuery.event.add.elemData.handle @ jquery.js:4333
```
Can you kindly help? @rzymek
opened 01:10PM - 06 May 16 UTC
closed 12:44PM - 14 May 16 UTC
Troubleshooting
TypeScript
``` javascript
function valid__isValid(m) {
if (m._isValid == null) {
… var flags = getParsingFlags(m);
var parsedParts = some.call(flags.parsedDateParts, function (i) {
return i != null;
});
m._isValid =
**m._d != null &&**
!isNaN(m._d.getTime()) &&
...
```
Without bold text (i wrote it), i had error when open chrome redux dev tools window
ERROR: cannot call getTime of undefined.
I think error happened when redux dev tools tries to call moment toJSON method.
Hi there - I’m having quite a perplexing issue that I can’t figure out.
I have a virgin project on 1.2.1 using the momentjs:moment package from Atmosphere.
When I call moment() in the browser console, I get a valid response, however, when I call moment() in code, then I get the following error in the console: Uncaught TypeError: m._d.getTime is not a function.
I’ve used moment before in previous projects with no problem, so I’m not sure why this isn’t working with a brand new project.
Any id…
a.com
January 3, 2017, 1:33pm
2
values.date is an object and you need to access values.date._d to get the ISOdate for passing to a meteor method.
const AddEventForm = Form.create()(React.createClass({
getInitialState () {
return {
loading: false
};
},
handleSubmit(e) {
e.preventDefault();
let data = { };
this.props.form.validateFields((error, values) => {
let { resourceType, stages, title, description, tags, location, date, clusters } = values
data = { resourceType, stages, title, description, tags, location, date._id, clusters };
//must pass date._d to method
Meteor.call('Events.addEvent', data, function(){
if (error) { failure(error); return; }
});
});
},
render() {
return (
<Form onSubmit={this.handleSubmit} className="login-form">
<FormItem>
{getFieldDecorator('date', {
rules: [{ required: true, message: 'Please input your location!' }],
})(
<DatePicker addonBefore={<Icon type="calendar" />} placeholder="event date" />
)}
</FormItem>
<Button type="primary" htmlType="submit">
Add Event
</Button>
</FormItem>
</Form>
);
},
}));
Just found myself on the exact same situation. If your form is big and you’re too lazy as me to copy all values. You can just encode and decode as JSON and re-date the date field(s).
const mapDispatchToProps = (dispatch) => {
return {
onFormSubmit(event) {
event.preventDefault()
this.validateFields((err, values) => {
if (!err) {
const data = JSON.parse(JSON.stringify(values))
data.date = new Date(data.date)
data.range = data.range.map(date => new Date(date))
dispatch(insertNotification(data))
}
})
}
}
}