Replies: 2 comments
-
That's more a question for Phoenix than for Flop. Based on the input component as generated by Phoenix 1.7, I like to define an additional Roughly, the function clause for the def input(%{type: "checkbox-group"} = assigns) do
~H"""
<div phx-feedback-for={@name <> "[]"}>
<fieldset>
<legend><%= @label %></legend>
<div class="checkbox-group">
<.label :for={option <- @options} class="checkbox"}>
<input
type="checkbox"
id={(@id || @name) <> "_#{option_value(option)}"}
name={@name <> "[]"}
value={option_value(option)}
checked={selected?(option_value(option), @value)}
{@rest}
/>
<span><%= option_label(option) %></span>
</.label>
</div>
</fieldset>
</div>
"""
end
defp option_label({label, _}), do: label
defp option_label(label), do: label
defp option_value({_, value}), do: value
defp option_value(value), do: value
defp selected?(option, value) when is_list(value) do
value_list = Enum.map(value, &html_escape/1)
html_escape(option) in value_list
end
defp selected?(option, value) do
html_escape(option) == html_escape(value)
end This is only a rough example adapted from a project. The basic idea is to end the checkbox name with %{
"filters" => %{
"0" => %{
"field" => "status_filter",
"op" => "in",
"value" => ["succeeded", "failed"]
}
}
} |
Beta Was this translation helpful? Give feedback.
-
Managed to get the desired behaviour with Edit: didn't see that you answered above. Will study it, thanks. |
Beta Was this translation helpful? Give feedback.
-
We want to implement this filter:
The schema is the following:
I want it to be an
ANY ()
query. Something like thisWHERE status ANY ('succeeded', 'running')
I think I need to get my params in such shape:
But I'm lost how to model it with checkboxes. Any ideas?
Beta Was this translation helpful? Give feedback.
All reactions