Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #159 from revelrylabs/handle-for-attribute
Browse files Browse the repository at this point in the history
handle 'for' attribute in single checkbox creation
  • Loading branch information
oohnoitz authored Feb 13, 2020
2 parents ef4cf67 + 40bb0c7 commit 5496a0a
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/harmonium.ex
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,15 @@ defmodule Harmonium do
end
end

@doc """
Renders an input label with a for attribute.
"""
def rev_label(f, key, modifiers, do: block) do
label f, key, class: rev_label_class(modifiers) do
block
end
end

@doc """
Renders an input label inner `<span>`.
"""
Expand Down Expand Up @@ -449,12 +458,12 @@ defmodule Harmonium do
Render a single checkbox.
iex> single_checkbox(f, :bool) |> safe_to_string()
"<label class=\\\"rev-InputLabel rev-Checkbox\\\"><input name=\\\"widget[bool]\\\" type=\\\"hidden\\\" value=\\\"false\\\"><input class=\\\"rev-Checkbox-input\\\" id=\\\"widget_bool\\\" name=\\\"widget[bool]\\\" type=\\\"checkbox\\\" value=\\\"true\\\"></label>"
"<label class=\\\"rev-InputLabel rev-Checkbox\\\" for=\\\"widget_bool\\\"><input name=\\\"widget[bool]\\\" type=\\\"hidden\\\" value=\\\"false\\\"><input class=\\\"rev-Checkbox-input\\\" id=\\\"widget_bool\\\" name=\\\"widget[bool]\\\" type=\\\"checkbox\\\" value=\\\"true\\\"></label>"
You may optionally add a label:
iex> single_checkbox(f, :bool, label: "Publish?") |> safe_to_string()
"<label class=\\\"rev-InputLabel rev-Checkbox\\\"><input name=\\\"widget[bool]\\\" type=\\\"hidden\\\" value=\\\"false\\\"><input class=\\\"rev-Checkbox-input\\\" id=\\\"widget_bool\\\" name=\\\"widget[bool]\\\" type=\\\"checkbox\\\" value=\\\"true\\\"><span class=\\\"rev-Checkbox-label\\\">Publish?</span></label>"
"<label class=\\\"rev-InputLabel rev-Checkbox\\\" for=\\\"widget_bool\\\"><input name=\\\"widget[bool]\\\" type=\\\"hidden\\\" value=\\\"false\\\"><input class=\\\"rev-Checkbox-input\\\" id=\\\"widget_bool\\\" name=\\\"widget[bool]\\\" type=\\\"checkbox\\\" value=\\\"true\\\"><span class=\\\"rev-Checkbox-label\\\">Publish?</span></label>"
"""
def single_checkbox(f, key, options \\ []) do
input_options =
Expand All @@ -475,7 +484,7 @@ defmodule Harmonium do
end
end

rev_label class: "rev-Checkbox" do
rev_label f, key, class: "rev-Checkbox" do
~E"<%= box %><%= label %>"
end
end
Expand Down

0 comments on commit 5496a0a

Please sign in to comment.