diff --git a/packages/core/admin/admin/src/content-manager/components/EditViewDataManagerProvider/index.js b/packages/core/admin/admin/src/content-manager/components/EditViewDataManagerProvider/index.js index cf86dfdd72..4aef4f8544 100644 --- a/packages/core/admin/admin/src/content-manager/components/EditViewDataManagerProvider/index.js +++ b/packages/core/admin/admin/src/content-manager/components/EditViewDataManagerProvider/index.js @@ -233,17 +233,20 @@ const EditViewDataManagerProvider = ({ ({ target: { name, value, type } }, shouldSetInitialValue = false) => { let inputValue = value; - // Empty string is not a valid date, - // Set the date to null when it's empty - if (type === 'date' && value === '') { + // Allow to reset text, string, email, uid, select/enum, date + if ( + (type === 'text' || + type === 'string' || + type === 'email' || + type === 'uid' || + type === 'select' || + type === 'select-one') && + value === '' + ) { inputValue = null; } - // Allow to reset text, string, email, uid - if ( - (type === 'text' || type === 'string' || type === 'email' || type === 'uid') && - value === '' - ) { + if (type === 'number' && !value) { inputValue = null; } @@ -256,16 +259,6 @@ const EditViewDataManagerProvider = ({ return; } - // Allow to reset enum - if (type === 'select-one' && value === '') { - inputValue = null; - } - - // Allow to reset number input - if (type === 'number' && value === '') { - inputValue = null; - } - dispatch({ type: 'ON_CHANGE', keys: name.split('.'), diff --git a/packages/core/helper-plugin/lib/src/components/GenericInput/index.js b/packages/core/helper-plugin/lib/src/components/GenericInput/index.js index 16c869c15d..3f8345987c 100644 --- a/packages/core/helper-plugin/lib/src/components/GenericInput/index.js +++ b/packages/core/helper-plugin/lib/src/components/GenericInput/index.js @@ -250,9 +250,7 @@ const GenericInput = ({ id={name} hint={hint} name={name} - onValueChange={value => { - onChange({ target: { name, value: value ?? null, type } }); - }} + onValueChange={value => onChange({ target: { name, value, type } })} placeholder={formattedPlaceholder} required={required} step={step} @@ -292,13 +290,7 @@ const GenericInput = ({ id={name} hint={hint} name={name} - onChange={event => { - if (event.target.value === '') { - onChange({ target: { name, value: null, type } }); - } else { - onChange({ target: { name, value: event.target.value, type } }); - } - }} + onChange={onChange} placeholder={formattedPlaceholder} required={required} type="text" @@ -358,9 +350,7 @@ const GenericInput = ({ id={name} hint={hint} name={name} - onChange={value => { - onChange({ target: { name, value: value === '' ? null : value, type: 'select' } }); - }} + onChange={value => onChange({ target: { name, value, type: 'select' } })} placeholder={formattedPlaceholder} required={required} value={value}