windexoriginal
- Why is there !!@current_scope on line 33 of the generated code? What is this accomplishing?
- Why is there a :let={f} on line 26? I see that is accessed on line 34, but I don’t understand why we can’t just use @form here and avoid the let?
For context here is are lines 25-44 of the generated login page:
<.form
:let={f} #why the let binding?
for={@form}
id="login_form_magic"
action={~p"/users/log-in"}
phx-submit="submit_magic"
>
<.input
readonly={!!@current_scope} #why the double negation?
field={f[:email]}
type="email"
label="Email"
autocomplete="username"
required
phx-mounted={JS.focus()}
/>
<.button class="w-full" variant="primary">
Log in with email <span aria-hidden="true">→</span>
</.button>
</.form>
This pattern is repeated for the second form for logging in with email and password. I’ve searched through the Phoenix documentation and I haven’t found anything helpful. I’ll admit I don’t grok the :letspecial attribute 100% so maybe that is the source of my confusion.
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted”
Version...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex










Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
codeanpeace
Probably to handle
nilvalues so when@current_scopeis not explicitly set, thereadonlyattribute gets set tofalse.I think it’s so that the login form submission can degrade gracefully by falling back to a regular HTTP request via the url specified by the
actionattribute.garrison
The login is always submitted via POST, the LiveView is just used for validation.
I don’t think that has anything to do with the
:letthough (unless there’s something I’m unaware of). It was changed from the@form[]syntax in this PR by @steffend - it’s a large diff with a lot going on, so it’s possible it just got left in as an oversight. Or perhaps it does something I’m not aware ofThe docs discourage the use of
:leton forms because it disables the fancy field change-tracking they added in LV1.0.steffend
The
:letis there because otherwise the inputs would have duplicate IDs, as we render the form twice. Another solution would be to assign two separate forms that already have an ID set.codeanpeace
Good to know, any idea what’s the purpose of
phx-submit="submit_magic"in that case?windexoriginal
My mind was in Elixir land where, in most cases, transforming
nilintofalsewouldn’t matter, but this makes sense for an HTML attribute.Thanks for the insight. I can say that the two form solution would be easier for me to read, but I’m glad to have learned something about reusing forms.
garrison
The form is submitted to the LiveView first for validation. If it passes validation, the LiveView uses phx-trigger-action to submit the form via POST to the session controller.
The form has to go through a POST because LiveView can’t set the session cookie. Only an HTTP request can set an HttpOnly cookie (the cookie is HttpOnly for security reasons).