View Source Readme
Spike.LiveView
provides a wrapper around
Phoenix.LiveView and
Phoenix.LiveComponent,
which simplifies working with memory-backed forms, including nested forms that require
contextual validation.
installation
Installation
Available in Hex, the package can be installed
by adding spike_liveview
to your list of dependencies in mix.exs
:
def deps do
[
{:spike_liveview, "~> 0.2"}
]
end
Documentation can be found at https://hexdocs.pm/spike_liveview.
quick-start
Quick start
Once installed in a Phoenix project, open up your *_web.ex
file and add the following
functions:
def form_live_view do
quote do
use Phoenix.LiveView,
layout: {MyAppWeb.LayoutView, "live.html"}
unquote(view_helpers())
use Spike.LiveView
end
end
def form_live_component do
quote do
use Phoenix.LiveComponent
unquote(view_helpers())
use Spike.LiveView
end
end
This allows you to build LiveViews and LiveComponents that ship with form and form erors handling capabilities out of the box by defining them as follows:
# for LiveView
defmodule MyApp.MyFormLive do
use MyAppWeb, :form_live_view
def mount(_params, _, socket) do
form = init_form()
{:ok,
socket
|> assign(%{form: form, errors: Spike.errors(form)})}
end
...
end
# for LiveComponent
defmodule MyApp.MyFormLiveComponent do
use MyAppWeb, :form_live_view
def mount(_params, _, socket) do
form = init_form()
{:ok,
socket
|> assign(%{form: form, errors: Spike.errors(form)})}
end
For starting point to build your own form components, see our Components Library.