woylie / flop_phoenix

Components for pagination, sortable tables and filter forms using Phoenix, Ecto and Flop
MIT License
405 stars 44 forks source link

Fix a bug in form field filtering #330

Open ponychicken opened 8 months ago

ponychicken commented 8 months ago

Fixes #204

The original implementation of the inputs_for_filters function indiscriminately zipped together the fields requested for filtering with their corresponding options without verifying if each field was actually permitted for filtering based on the form's schema.

If the fields requested were [1,2,3] and to_form returned only [2,3] then these two lists would be zipped together resulting in something like [[1,2], [2,3]] instead of [1,1],[2,2].

To fix loop through the fields individually, call to_form on them and only combine them with the opts if to_form returns something.

ponychicken commented 8 months ago

no, there is a problem yet, since calling to_form individually will result in all fields having index=0. Maybe have a look how you would fix the issue with zip best.

woylie commented 8 months ago

Thank you for opening the PR. I didn't have a close look at your changes yet, but one way to solve this might be to pass the index to the to_form function as an option.

ponychicken commented 8 months ago

Thank you for opening the PR. I didn't have a close look at your changes yet, but one way to solve this might be to pass the index to the to_form function as an option.

Yes, that was my first thought to just use the offset parameter, but then there will be still gaps in the indexes. So I was too tired to continue looking, but in the end I thought that probably there is no way around restructuring the to_form function.