Checkbox groups send an empty string
The checkbox-group component has an hidden input with an empty value:
https://github.com/petalframework/petal_components/blame/23ec5d208826311645808c42913fd2dc7e9bee41/lib/petal_components/field.ex#L240
This produces values like this in LiveView (notice the empty string):
dbg(params)
=> %{"my-group" => ["", "things", "i", "checked"]}
Which is kinda crashing our logic. We didn't have this issue before the upgrade to v3. What is the rationale behind the hidden input?
The hidden input in checkbox groups is a standard HTML pattern to ensure the form parameter is always sent even when no checkboxes are selected. However, the empty string can be removed from the implementation. To fix this, modify lib/petal_components/field.ex line 240 to either: 1. Remove the empty value: elixir <input type="hidden" name={@name} value="" /> to elixir <input type="hidden" name={@name} /> 2. Or filter out empty strings in your form handling: elixir params["my-group"] |> Enum.reject(&(&1 == "")) The hidden input ensures the parameter exists in the form data even when no boxes are checked, but the empty value is not strictly necessary.
About Greptile
This response provides a starting point for your research, not a precise solution.
Help us improve! Please leave a ๐ if this is helpful and ๐ if it is irrelevant.
The hidden input in checkbox groups is a standard HTML pattern to ensure the form parameter is always sent even when no checkboxes are selected.
https://github.com/petalframework/petal_components/commit/8715c035db8dd7fdaf0f80fdd6ef9f0d1bbae7e7
So then this commit is wrong? Because now the empty value is being set as the default first element in the list, while it was meant as a fallback when no checkboxes are checked?