wintercms/winter

Multiple default filters interfere with each other

AIC-BV opened this issue · 6 comments

Winter CMS Build

dev-develop

PHP Version

8.1

Database engine

MySQL/MariaDB

Plugins installed

No response

Issue description

When you have multiple defined default filters in config_filter.yaml and do the following action:

  1. CLEAR the first
  2. CLEAR the second
  3. Both are CLEARED visually, but in fact, the first has been reset to its default value! It is impossible to clear both filters!
approved_status:
        label: Approved status
        type: group
        conditions: approved_status in (:filtered)
        options:
           'x': X
           'y': Y
           'z': Z
        default:
            'x': X

    shipped_status:
        label: Shipped status
        type: group
        conditions: shipped_status in (:filtered)
        options:
            1: Shipped
            0: Not shipped
        default:
            0: Shipped
  1. image
  2. image
  3. image

Steps to replicate

See description

Workaround

No response

Also, when you have default filters (doesn't matter wether its single or multiple), clear them, and go to the next page, the filters get reapplied and you can never go to the second page

I believe the same happens when you clear and search for something.

@AIC-BV could you test if this commit has anything to do with this?

4847f8b

@AIC-BV could you test if this commit has anything to do with this?

4847f8b

I changed my files and ran php artisan winter:util compile js but I don't notice any changes. Still not working. Must be broken for years now and an unused functionality 😅

The problem would be that when a filter is empty, it would instead apply the default value. There's no way for a filter to send a POST value to indicate it is empty and not populate the default value.

I had the same issue with an ecommerce site (being able to filter between order status as well as completed or incomplete orders), and I had to change the "completed" filter to a checkbox that, when ticked, only included "completed" orders. You could possibly do the same with your "shipped" filter.

EDIT: These were the scopes I used

scopes:
    paid:
        label: Completed orders only
        type: checkbox
        default: 1
        conditions: placed_at IS NOT NULL

    status:
        label: Status
        type: group
        scope: isStatus
        modelClass: \BennoThommo\Snowcart\Models\Status
        options: getList

    placed_at:
        label: Placed at
        type: daterange
        yearRange: 10
        conditions: DATE(placed_at) >= ':afterDate' AND DATE(placed_at) <= ':beforeDate'
scopes:
    paid:
        label: Completed orders only
        type: checkbox
        default: 1
        conditions: placed_at IS NOT NULL

I'm not entirely following:

  1. Here you have paid -> default: 1.
  2. When you uncheck this, and 'search' on the top right, or go to the next page, it will secretly be checked again.
  3. Meaning you can never see records with paid value 0 on the 2nd page or by search.

Or does the checkbox avoid this problem..?

Sorry for the delay @AIC-BV. As I recall, my setup above didn't exhibit any problems when switching pages. If you're willing, would you mind providing us an example in the Test plugin?