summaryrefslogtreecommitdiff
path: root/lib/aggiedit_web/live/post_live/form_component.html.heex
blob: a956cb34f7c68a97d0133a6cd41874938ec3f5ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<div>
  <h2><%= @title %></h2>

  <.form
    let={f}
    for={@changeset}
    id="post-form"
    phx-target={@myself}
    phx-change="validate"
    phx-submit="save">
  
    <%= label f, :title %>
    <%= textarea f, :title %>
    <%= error_tag f, :title %>
  
    <%= label f, :body %>
    <%= textarea f, :body %>
    <%= error_tag f, :body %>

    <%= if !Ecto.assoc_loaded?(@post.upload) do %>
      <%= live_file_input @uploads.upload %>
      <%= for upload <- @uploads.upload.entries do %>
        <div class="row">
          <div class="column">
            <%= live_img_preview upload, height: 80 %>
          </div>
        </div>
      <% end %>
    <%= else %>
      <% if !is_nil(@post.upload) do %>
        <div class="row">
          <div class="column">
            <img style="height:80px" src={Routes.static_path(@socket, "/uploads/#{@post.upload.file}")} />
          </div>
        </div>
      <% end %>
    <% end %>
  
    <div>
      <%= submit "Save", phx_disable_with: "Saving..." %>
    </div>
  </.form>
</div>