Don't treat nullish values as default values, to allow clearing fields even when a default value is set
This commit is contained in:
parent
8b48ddc227
commit
9f2451e829
|
@ -92,21 +92,19 @@
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const newValue = value == null ? defaultValue : value
|
|
||||||
const newError = validate ? validate(newValue) : null
|
|
||||||
|
|
||||||
// Update field state
|
// Update field state
|
||||||
|
const error = validate ? validate(value) : null
|
||||||
fieldState.update(state => {
|
fieldState.update(state => {
|
||||||
state.value = newValue
|
state.value = value
|
||||||
state.error = newError
|
state.error = error
|
||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
|
|
||||||
// Update form state
|
// Update form state
|
||||||
formState.update(state => {
|
formState.update(state => {
|
||||||
state.values = { ...state.values, [field]: newValue }
|
state.values = { ...state.values, [field]: value }
|
||||||
if (newError) {
|
if (error) {
|
||||||
state.errors = { ...state.errors, [field]: newError }
|
state.errors = { ...state.errors, [field]: error }
|
||||||
} else {
|
} else {
|
||||||
delete state.errors[field]
|
delete state.errors[field]
|
||||||
}
|
}
|
||||||
|
@ -114,7 +112,7 @@
|
||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
|
|
||||||
return !newError
|
return !error
|
||||||
}
|
}
|
||||||
|
|
||||||
const clearValue = () => {
|
const clearValue = () => {
|
||||||
|
|
Loading…
Reference in New Issue