This commit is contained in:
soupette 2019-09-13 14:46:31 +02:00
parent 8970159ffa
commit 9ad9fafd6b
4 changed files with 23 additions and 24 deletions

View File

@ -60,6 +60,7 @@ function InputDate(props) {
target: {
name: props.name,
value: moment,
type: 'date',
},
})
}

View File

@ -117,7 +117,7 @@ class InputToggleWithErrors extends React.Component {
InputToggleWithErrors.defaultProps = {
autoFocus: false,
className: '',
customBootstrapClass: 'col-md-6',
customBootstrapClass: 'col-md-4',
deactivateErrorHighlight: false,
didCheckErrors: false,
disabled: false,

View File

@ -212,6 +212,22 @@ function EditView({
});
};
const handleChange = ({ target: { name, value, type } }) => {
let inputValue = value;
// Empty string is not a valid date,
// Set the date to null when it's empty
if (type === 'date' && value === '') {
inputValue = null;
}
dispatch({
type: 'ON_CHANGE',
keys: name.split('.'),
value: inputValue,
});
};
const handleSubmit = async e => {
e.preventDefault();
const schema = createYupSchema(layout, { groups: groupLayoutsData });
@ -278,7 +294,6 @@ function EditView({
strapi.notification.error(error);
}
} catch (err) {
console.log({ formErrors: err });
setIsSubmitting(false);
const errors = get(err, 'inner', []).reduce((acc, curr) => {
acc[
@ -291,6 +306,7 @@ function EditView({
return acc;
}, {});
dispatch({
type: 'SET_ERRORS',
errors,
@ -322,13 +338,7 @@ function EditView({
keys: name.split('.'),
});
}}
onChange={({ target: { name, value } }) => {
dispatch({
type: 'ON_CHANGE',
keys: name.split('.'),
value,
});
}}
onChange={handleChange}
onRemove={keys => {
dispatch({
type: 'REMOVE_RELATION',
@ -448,13 +458,7 @@ function EditView({
keys: name.split('.'),
});
}}
onChange={({ target: { name, value } }) => {
dispatch({
type: 'ON_CHANGE',
keys: name.split('.'),
value,
});
}}
onChange={handleChange}
layout={get(groupLayoutsData, group.group, {})}
pathname={pathname}
removeField={(keys, shouldAddEmptyField) => {
@ -481,13 +485,7 @@ function EditView({
layout={layout}
modifiedData={modifiedData}
name={name}
onChange={({ target: { name, value } }) => {
dispatch({
type: 'ON_CHANGE',
keys: name.split('.'),
value,
});
}}
onChange={handleChange}
/>
);
})}

View File

@ -130,7 +130,7 @@ const createYupSchemaAttribute = (type, validations) => {
.typeError();
}
if (['date', 'datetime'].includes(type)) {
schema = yup.date().typeError();
schema = yup.date();
}
Object.keys(validations).forEach(validation => {