laravel / nova-issues

554 stars 35 forks source link

Number field doesn't honor nullable #6477

Closed niekdemelker closed 1 month ago

niekdemelker commented 1 month ago

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.

crynobone commented 1 month ago

Please provide full reproducing repository based on fresh installation as suggested in the bug report template (or you can refer to https://github.com/nova-issues for example)

niekdemelker commented 1 month ago

Sure thing. I made a repository: https://github.com/niekdemelker/issue-6477/blob/e44d4c26994c58364475d5a3c4108c1b5e48dd72/app/Nova/User.php#L62

the 'Bugged Value' should have the same look as the 'Tester' value, but it doesn't.

To see it: run migrations create nova user go to user index in nova to see the bug

github-actions[bot] commented 3 weeks ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.