nova-enum-field icon indicating copy to clipboard operation
nova-enum-field copied to clipboard

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

Open asugai opened this issue 3 years ago • 4 comments

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:

  • Check off 1 enum filter option
  • See "Selected Filter Counter" change to "1" and background color change from "white" to "green"
  • Uncheck the enum filter option
  • See "Selected Filter Counter" stay at "1" and background color stays "green"

Expected results:

  • See "Selected Filter Counter" show no counter and background color change back to "white"
Screenshot 2022-12-12 at 10 16 20 PM

asugai avatar Dec 13 '22 04:12 asugai

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

mdpoulter avatar Feb 16 '23 19:02 mdpoulter

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

zatorck avatar Mar 14 '23 18:03 zatorck

Sure!

mdpoulter avatar Mar 19 '23 11:03 mdpoulter

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.

zatorck avatar Apr 02 '23 15:04 zatorck

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

mdpoulter avatar Jun 16 '24 13:06 mdpoulter