Merge pull request #2659 from strapi/fix/#1960

Fix InputDate not working
This commit is contained in:
Jim LAURIE 2019-01-30 17:39:46 +01:00 committed by GitHub
commit ea3a7da846
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 7 deletions

View File

@ -171,6 +171,7 @@ InputDateWithErrors.defaultProps = {
style: {},
tabIndex: '0',
validations: {},
value: null,
};
InputDateWithErrors.propTypes = {
@ -217,7 +218,10 @@ InputDateWithErrors.propTypes = {
style: PropTypes.object,
tabIndex: PropTypes.string,
validations: PropTypes.object,
value: PropTypes.string.isRequired,
value: PropTypes.oneOfType([
PropTypes.string,
PropTypes.object,
]),
};
export default InputDateWithErrors;

View File

@ -5,7 +5,6 @@
*/
import React from 'react';
import moment from 'moment';
import { connect } from 'react-redux';
import { bindActionCreators, compose } from 'redux';
import { createStructuredSelector } from 'reselect';
@ -16,7 +15,6 @@ import {
get,
includes,
isEmpty,
isObject,
toNumber,
toString,
replace,
@ -260,9 +258,7 @@ export class EditPage extends React.Component {
handleChange = e => {
let value = e.target.value;
// Check if date
if (isObject(e.target.value) && e.target.value._isAMomentObject === true) {
value = moment(e.target.value).format('YYYY-MM-DD HH:mm:ss');
} else if (
if (
['float', 'integer', 'biginteger', 'decimal'].indexOf(
get(this.getSchema(), ['fields', e.target.name, 'type']),
) !== -1

View File

@ -88,8 +88,18 @@ export function* submit() {
yield put(setLoader());
const recordCleaned = Object.keys(record).reduce((acc, current) => {
const attrType = source !== 'content-manager' ? get(schema, ['models', 'plugins', source, currentModelName, 'fields', current, 'type'], null) : get(schema, ['models', currentModelName, 'fields', current, 'type'], null);
const cleanedData = attrType === 'json' ? record[current] : cleanData(record[current], 'value', 'id');
let cleanedData;
switch (attrType) {
case 'json':
cleanedData = record[current];
break;
case 'date':
cleanedData = record[current]._isAMomentObject === true ? record[current].format('YYYY-MM-DD HH:mm:ss') : record[current];
break;
default:
cleanedData = cleanData(record[current], 'value', 'id');
}
if (isString(cleanedData) || isNumber(cleanedData)) {
acc.append(current, cleanedData);