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

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

Open
zw963 opened this issue Jul 2, 2024 · 0 comments
Labels

Comments

@zw963
Copy link

zw963 commented Jul 2, 2024

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.

@zw963 zw963 added the bug label Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant