nova-issues icon indicating copy to clipboard operation
nova-issues copied to clipboard

Number field doesn't honor nullable

Open niekdemelker opened this issue 1 year ago • 2 comments

  • Laravel Version: 11.17.0
  • Nova Version: 4.34.3
  • PHP Version: 8.3.9

Description:

I tried making a Nova Lens to show some license counts. Because some of these record have a zero value i wanted to convert this to null. I did this by applying the following

Number::make('Count')->nullable(values: [0, '', 'null', null])

Only the result in nova displays '0' instead of '—', displaying the true value.

If I revert the logic and make something like this

Number::make('Count')
    ->displayUsing(fn ($amount) => $amount ?? "0")

The null value will be shown as '0'.

This could be solved by making a computed property, only then I will lose the ability to sort the field, which is a must.

Detailed steps to reproduce the issue on a fresh Nova installation:

Create a number field like above, and make sure the DB returns a '0' (zero) value.

niekdemelker avatar Jul 24 '24 21:07 niekdemelker