fix(ui): number field not being able to clear out the field's value (#8425)

Fixes #7780 

Fixes a bug where the number field won't save data if it's being removed
entirely (should be null) instead of changed to another value.

---------

Co-authored-by: PatrikKozak <patrik@payloadcms.com>
This commit is contained in:
Paul
2024-09-26 08:37:23 -06:00
committed by GitHub
parent 84d2026330
commit 5c2e39ef0c
2 changed files with 13 additions and 1 deletions

View File

@@ -78,7 +78,7 @@ const NumberFieldComponent: NumberFieldClientComponent = (props) => {
let newVal = val
if (Number.isNaN(val)) {
newVal = undefined
newVal = null
}
if (typeof onChangeFromProps === 'function') {

View File

@@ -138,4 +138,16 @@ describe('Number', () => {
'The following field is invalid: withMinRows',
)
})
test('should keep data removed on save if deleted', async () => {
const input = 1
await page.goto(url.create)
const field = page.locator('#field-number')
await field.fill(String(input))
await saveDocAndAssert(page)
await expect(field).toHaveValue(String(input))
await field.fill('')
await saveDocAndAssert(page)
await expect(field).toHaveValue('')
})
})