simplesquid / nova-enum-field

An enum field and filters for Laravel Nova.
MIT License
52 stars 26 forks source link

Filter shows selected enum option even when all enum options are unchecked #53

Closed asugai closed 2 months ago

asugai commented 1 year ago

Laravel v9.41.0 Nova v4.19.3 Nova Enum Field v3.0.1

Issue: The Filter dropdown shows that an enum filter is selected even when filters have been unchecked.

Steps to reproduce:

Expected results:

Screenshot 2022-12-12 at 10 16 20 PM
mdpoulter commented 1 year ago

Seemed to have missed this over the holidays! Happy with a PR that resolves this 😄

zatorck commented 1 year ago

Hey, do you still need PR for that? I can try to do it.

mdpoulter commented 1 year ago

Sure!

zatorck commented 1 year ago

I already found that workaround for that is not to use "0" as value of enum. eg. const Admin = 0;.

UPDATE:

For me it's rather Nova itself bug then this package. Take this as simple example - it gives exactly the same behaviour:

<?php

namespace App\Nova\Filters;

use Laravel\Nova\Filters\BooleanFilter;
use Laravel\Nova\Http\Requests\NovaRequest;

class ExampleType extends BooleanFilter
{

    public function apply(NovaRequest $request, $query, $value)
    {
        return $query;
    }

    public function options(NovaRequest $request)
    {
        return [0,1,2];
    }
}

What do you guys think? In above example you can change return in options method to [1,2] and it starts to work as expected.

mdpoulter commented 2 months ago

Closing this if this behaviour is present in Nova itself. Thanks for the investigation!