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

Form.datetime_select/3 builder example uses deprecated ~e sigil #363

Closed
michallepicki opened this issue Nov 22, 2021 · 5 comments · Fixed by #364
Closed

Form.datetime_select/3 builder example uses deprecated ~e sigil #363

michallepicki opened this issue Nov 22, 2021 · 5 comments · Fixed by #364

Comments

@michallepicki
Copy link
Contributor

https://hexdocs.pm/phoenix_html/3.1.0/Phoenix.HTML.Form.html#datetime_select/3-builder
The def my_datetime_select example should probably use a ~H sigil?

@josevalim
Copy link
Member

@michallepicki can you please check if it works with ~H, and if it does, send a PR? Thank you.

@michallepicki
Copy link
Contributor Author

michallepicki commented Nov 22, 2021

@michallepicki sorry, I couldn't figure it out, I settled on html_escape for my use case for now (I'm using it in a regular dead view)

@josevalim
Copy link
Member

Did you get an error or something?

@michallepicki
Copy link
Contributor Author

  def my_datetime_select(form, field, opts \\ []) do
    builder = fn b ->
      ~H"""
      Date: <%= b.(:day, []) %> / <%= b.(:month, []) %> / <%= b.(:year, []) %>
      Time: <%= b.(:hour, []) %> : <%= b.(:minute, []) %>
      """
    end

    datetime_select(form, field, [builder: builder] ++ opts)
  end

Error:

warning: variable "assigns" does not exist and is being expanded to "assigns()", please use parentheses to remove the ambiguity or change the variable name
  lib/ui/views/users_view.ex:81: UI.UsersView.my_datetime_select/3


== Compilation error in file lib/ui/views/users_view.ex ==
** (CompileError) lib/ui/views/users_view.ex:81: undefined function assigns/0
    (elixir 1.12.2) src/elixir_locals.erl:114: anonymous fn/3 in :elixir_locals.ensure_no_undefined_local/3
    (stdlib 3.15.2) erl_eval.erl:685: :erl_eval.do_apply/6

Maybe this needs to be a functional Phoenix.Component? Not sure how/if that would work, I don't have experience with them yet

@josevalim
Copy link
Member

you always need an assigns attribute before, something like this would work:

assigns = %{b: b}

~H"""
"""

and then you use @b inside.

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

Successfully merging a pull request may close this issue.

2 participants