Rbtz. CredoChecks. Warning. LiveViewFormCanBeRehydrated
(rbtz_credo_checks v0.4.0)
Copy Markdown
View Source
Basics
This check is disabled by default.
Learn how to enable it via .credo.exs.
This check has a base priority of high and works with any version of Elixir.
Explanation
Ensures that LiveView forms (i.e. forms with phx-submit) carry both an
id attribute and a phx-change attribute.
Without these two attributes, LiveView cannot rehydrate the form's state
across reconnects or live patches: the user's input is silently lost when
the form is re-rendered. The id lets LiveView identify the form across
renders, and phx-change keeps the server-side form data in sync with
the user's keystrokes so it can be replayed.
Forms without phx-submit are not driven by LiveView and are exempt.
Bad
<.form for={@form} phx-submit="save">
<.input field={@form[:name]} />
</.form>
<form phx-submit="save">
<input name="name" />
</form>Good
<.form for={@form} id="profile-form" phx-submit="save" phx-change="validate">
<.input field={@form[:name]} />
</.form>The check scans ~H sigils and .heex template files referenced by
embed_templates.
Check-Specific Parameters
There are no specific parameters for this check.
General Parameters
Like with all checks, general params can be applied.
Parameters can be configured via the .credo.exs config file.