Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove default parameters #250

Open
woylie opened this issue Aug 4, 2023 · 2 comments
Open

remove default parameters #250

woylie opened this issue Aug 4, 2023 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@woylie
Copy link
Owner

woylie commented Aug 4, 2023

build_path/3 and to_query/2 don't include default parameters, but there is no easy way to remove the default parameters from an already existing parameter map. A remove_defaults or clean_params function might be a good addition.

That would allow us to do something like:

def handle_event("update-filter", params, socket) do
  params = Flop.Phoenix.clean_params(params, socket.assigns.meta)
  {:noreply, push_patch(socket, to: ~p"/pets?#{params}")}
end

The function should be able to take either a keyword list for the for and/or backend options or a meta struct from which it can get those options.

@woylie woylie self-assigned this Aug 4, 2023
@woylie woylie added this to the 0.22.0 milestone Aug 4, 2023
@woylie woylie added the enhancement New feature or request label Aug 4, 2023
@vanderhoop
Copy link
Contributor

Is the user-facing benefit of this change that unused filters wouldn't end up in the params? For example, I've noticed that all filter_fields end up in the params, regardless of whether they have a (pre-populated or user-selected) value.

@woylie
Copy link
Owner Author

woylie commented Aug 5, 2023

Yes, that's the idea. The filter form is a just a regular HTML form, so it will generate parameters for each input, whether it is filled or not. We cannot change this on the component side, but we can clean the parameters up in the handle_event callback. Also, it is opt-in this way. It wouldn't work with dynamic forms.

@woylie woylie removed this from the 0.22.0 milestone Sep 26, 2023
@linear linear bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 16, 2024
@woylie woylie reopened this Jun 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants