prefill award label (#5)

This commit is contained in:
byte[] 2020-09-14 20:12:27 -04:00
parent 6deab827ac
commit 504b1d5b82
2 changed files with 12 additions and 2 deletions

View file

@ -1,16 +1,18 @@
= form_for @changeset, @action, fn f ->
- badge_options = badge_options(@badges)
= if @changeset.action do
.alert.alert-danger
p Oops, something went wrong! Please check the errors below.
.field
=> label f, :badge_id, "Badge type"
= select f, :badge_id, badge_options(@badges), class: "input", data: [change_selectvalue: "#award_label"]
= select f, :badge_id, badge_options, class: "input", data: [change_selectvalue: "#award_label"]
= error_tag f, :badge_id
.field
=> label f, :label, "Label (Public)"
= text_input f, :label, class: "input input--wide"
= text_input f, :label, class: "input input--wide", value: first_badge_label(badge_options)
= error_tag f, :label
.field

View file

@ -10,4 +10,12 @@ defmodule PhilomenaWeb.Profile.AwardView do
]
end
end
def first_badge_label([]) do
nil
end
def first_badge_label([badge | _rest]) do
badge[:data][:set_value]
end
end