feedback fix - number/select empty value checked in EditViewDataManagerProvider

This commit is contained in:
ronronscelestes 2022-05-25 14:59:19 +02:00
parent 681b21786c
commit aff13a0d60
2 changed files with 14 additions and 31 deletions

View File

@ -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('.'),

View File

@ -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}