moonshine-software / moonshine

Laravel Admin panel and more. Simple for beginners and powerful for experts. Using Blade, Alpine.js and Tailwind CSS.
https://moonshine-laravel.com
MIT License
759 stars 100 forks source link

Title: DateRange and RangeSlider fields in filters submit empty values #1194

Closed savosik closed 2 months ago

savosik commented 2 months ago

MoonShine Version

2.20.7

Laravel Version

10.4.1

PHP Version

8.2

Database Driver & Version

No response

Description

When using DateRange and RangeSlider fields in filters, even when no values are selected, these fields are being submitted with the form. This causes two issues:

  1. Empty values for these fields are included in the GET request URL.
  2. The "Selected Filters" button shows an incorrect count, including these empty range fields as if they were set.

Expected Behavior

  1. The GET request URL should not include parameters for empty DateRange and RangeSlider fields.
  2. The "Selected Filters" count should only include fields that actually have values set.

Actual Behavior

  1. The GET request URL includes parameters for DateRange and RangeSlider fields even when they are empty.
  2. The "Selected Filters" count includes these empty range fields, showing an inflated number.

Additional Context

This behavior can lead to confusion for users, as it appears that filters are applied when they actually aren't. It also affects the accuracy of the filter count display.

Possible Solution

Modify the form submission process for DateRange and RangeSlider fields to only include them in the GET request and filter count if they have actual values set.

Steps To Reproduce

  1. Create a filter using DateRange and/or RangeSlider fields.
  2. Load the page with the filter.
  3. Without selecting any values for these range fields, submit the filter form.
lee-to commented 2 months ago

This is the native behaviour of HTML forms, if they are posted, then everything flies into the request and, accordingly, if there are values ​​there, then they will affect the counter, if you want to change the native behaviour of forms, then add your own JS or suggest PR.