Skip to content

Commit

Permalink
prefill award label (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
liamwhite committed Sep 15, 2020
1 parent 6deab82 commit 504b1d5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/philomena_web/templates/profile/award/_form.html.slime
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 8 additions & 0 deletions lib/philomena_web/views/profile/award_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 504b1d5

Please sign in to comment.