Skip to content
Permalink
Browse files

Phoenix.HTML

  • Loading branch information...
dnsbty committed Aug 18, 2019
1 parent 19683bc commit 42309f04150c7db6bda554c034ac703aadd88169
@@ -1,2 +1,11 @@
defmodule UserAdmin.Users do
alias UserAdmin.Users.User

@doc """
Create a changeset to change a user.
"""
@spec change_user(User.t(), map()) :: Ecto.Changeset.t()
def change_user(user, changes \\ %{}) do
User.changeset(user, changes)
end
end
@@ -1,10 +1,17 @@
defmodule UserAdmin.Users.User do
use Ecto.Schema
alias UserAdmin.Users.Role
import Ecto.Changeset

schema "users" do
field :name, :string

belongs_to :role, Role
end

def changeset(user, changes \\ %{}) do
user
|> cast(changes, [:name])
|> validate_required([:name])
end
end
@@ -1,9 +1,13 @@
defmodule UserAdminWeb.UserLive.New do
use Phoenix.LiveView
alias UserAdminWeb.UserView
alias UserAdmin.Users
alias UserAdmin.Users.User

def mount(_session, socket) do
{:ok, socket}
changeset = Users.change_user(%User{})

{:ok, assign(socket, changeset: changeset)}
end

def render(assigns) do
@@ -1,17 +1,18 @@
<h2>New User</h2>
<form>
<%= f = form_for @changeset, "#", phx_submit: :create %>
<fieldset>
<label for="nameField">Name</label>
<input type="text" id="nameField">
<%= label f, :name, for: "nameField" %>
<%= text_input f, :name, id: "nameField" %>

<label for="roleField">Role</label>
<select id="roleField">
<option value="admin">Administrator</option>
<option value="mod">Moderator</option>
<option value="user">User</option>
<option value="guest">Guest</option>
</select>

<div>
<input type="submit" value="Create">
<%= submit "Create", phx_disable_with: "Creating..." %>
</div>
</fieldset>
</form>

0 comments on commit 42309f0

Please sign in to comment.
You can’t perform that action at this time.