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

Using :values={some_value: "yes"} will dasherize key to "some-value" #562

Open
theycallmehero opened this issue Jan 21, 2022 · 6 comments
Open

Comments

@theycallmehero
Copy link

Is there some reason why this happens and url params should be dasherized?

@Coffei
Copy link

Coffei commented Feb 9, 2022

Would also like to know the answer to this, started seeing this after upgrading to 0.7. The :values above is rendered as phx-value-some-value="yes", while in 0.5.1 it was rendered as phx-value-some_value="yes" causing issues in handle_event callbacks of our existing code.

@hubertlepicki
Copy link
Contributor

Yep, I have an app where we use things like phx-value-database_field_name that I just tried updating to 0.7 and indeed this is happening again. #512 had this solved. Investigating what's going on now.

@hubertlepicki
Copy link
Contributor

hubertlepicki commented Mar 11, 2022

so @margusp2heathmont and @Coffei , I made this supported on the phoenix_html level, as this is what takes care of these conversions. I think we all update from 0.5 to 0.7 here, and in fact it was probably the same issue on 0.6.

Anyway, the fix that I have to make in my app and you in yours is to replace the following code:

<Link label="user" to="/users/1" opts={ "phx-click" => "my_click", "phx-value-user_id" => 1 } />

with

<Link label="user" to="/users/1" opts={ phx: [click: "my_click", value: [{"user_id", 1}]] } />

as this was implemented to support this new syntax here:

phoenixframework/phoenix_html@0f2c4f3

If you don't make it a nested list, and keep using "phx-some_thing", this "some_thing" unfortunately will be turned into "some-thing" on the phoenix_html level.

@Coffei
Copy link

Coffei commented Mar 11, 2022

Thanks for the update!

I am not using phx-value directly but rather Surface helper :values. I assume that means Surface has to do the same and transform :values into the second form you posted not the first.

@hubertlepicki
Copy link
Contributor

hubertlepicki commented Mar 11, 2022

@Coffei does it work if you replace your map that you pass to values with keyword list? (I'm not saying it will work)

@Coffei
Copy link

Coffei commented Mar 11, 2022

Hmm.. I use :values={type_index: @type_index, def_index: @def_index, to: "script"} which I assume already is a keyword list. Still I tried :values={[type_index: @type_index, def_index: @def_index, to: "script"]} and :values={%{type_index: @type_index, def_index: @def_index, to: "script"}} and all of them behave the same. They render to

<a phx-value-def-index="0" phx-value-to="script" phx-value-type-index="0" ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants