luckyframework/lucky

Couldn't get the correct param value when work with htmx + checkbox when return two same name attribute's value.

zw963 opened this issue · 0 comments

Copied from #1903

When worked with builtin checkbox method + a model column, lucky will generate a hidden input element which use same name attribute value, like following:

<form>
  <input type="hidden" name="university:chong_2023" value="false">
  <input type="checkbox" id="chong_2023" name="university:chong_2023" value="true" hx-put="/universities/843"
</form>

it work as expected.

When when work with htmx which not a form, like this:

label do
            input(type: "hidden", name: "university:is_marked", value: "false", id: "marked_unmark")
            input(
              type: "checkbox",
              name: "university:is_marked",
              value: "true",
              id: "marked",
              "hx-put": "",
              "hx-target": "",
              "hx-swap": "outerHTML",
              "hx-indicator": "#spinner",
              "hx-include": "[name='_csrf'],[name='university:is_marked']"
            )
            span "手动"
          end

I get following params.body when checkbox checked

web          | params.body # => "university%3Ais_marked=true&university%3Ais_marked=false"

And get following when unchecked

web          | params.body # => "university%3Ais_marked=false"

The issue is, on both cases, params.to_h always return false, like following

web          | params.to_h # => {"university" => {"is_marked" => "false"},
web          |  "_csrf" => "UzxOfKACL6XbS0PZn10tih4Tg0eEVjD6oPdMJBBVRo0"} 

my question is, how to get the true value of is_marked when request.body is "university%3Ais_marked=true&university%3Ais_marked=false"?

Thanks.