This commit is contained in:
soupette 2019-01-20 14:21:38 +01:00
parent 80d13dff9c
commit 4a160b04fd
3 changed files with 18 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

@ -1,4 +1,5 @@
import { LOCATION_CHANGE } from 'react-router-redux';
import moment from 'moment';
import { findIndex, get, isArray, isEmpty, includes, isNumber, isString, map } from 'lodash';
import {
all,
@ -88,8 +89,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 = moment(record[current]).format();
break;
default:
cleanedData = cleanData(record[current], 'value', 'id');
}
if (isString(cleanedData) || isNumber(cleanedData)) {
acc.append(current, cleanedData);