diff --git a/lib/philomena_web/templates/image/new.html.slime b/lib/philomena_web/templates/image/new.html.slime index dd5fef2e..e9db71c4 100644 --- a/lib/philomena_web/templates/image/new.html.slime +++ b/lib/philomena_web/templates/image/new.html.slime @@ -65,7 +65,7 @@ .field .block .communication-edit__wrap - = render PhilomenaWeb.MarkdownView, "_input.html", conn: @conn, f: f, action_icon: "pencil-alt", action_text: "Description", placeholder: "Describe this image in plain words - this should generally be info about the image that doesn't belong in the tags or source.", required: false + = render PhilomenaWeb.MarkdownView, "_input.html", conn: @conn, f: f, action_icon: "pencil-alt", action_text: "Description", placeholder: "Describe this image in plain words - this should generally be info about the image that doesn't belong in the tags or source.", name: :description, class: "js-image-input", required: false = render PhilomenaWeb.MarkdownView, "_anon_checkbox.html", conn: @conn, f: f, label: "Post anonymously" diff --git a/lib/philomena_web/templates/markdown/_input.html.slime b/lib/philomena_web/templates/markdown/_input.html.slime index 72b1182a..8ec1ae19 100644 --- a/lib/philomena_web/templates/markdown/_input.html.slime +++ b/lib/philomena_web/templates/markdown/_input.html.slime @@ -3,6 +3,8 @@ - action_icon = assigns[:action_icon] || 'edit' - field_name = assigns[:name] || :body - field_placeholder = assigns[:placeholder] || "Your message" +- is_required = assigns[:required] +- input_classes = assigns[:class] .block__header.block__header--js-tabbed a.selected href="#" data-click-tab="write" i.fa> class="fa-#{action_icon}" @@ -18,7 +20,7 @@ = render PhilomenaWeb.MarkdownView, "_toolbar.html", conn: @conn .field - = textarea form, field_name, class: "input input--wide input--text input--resize-vertical js-toolbar-input js-preview-input", placeholder: field_placeholder, required: required?(@conn) + = textarea form, field_name, class: add_classes("input input--wide input--text input--resize-vertical js-toolbar-input js-preview-input", input_classes), placeholder: field_placeholder, required: required?(is_required) = error_tag form, field_name .block__tab.communication-edit__tab.hidden.js-preview-content data-tab="preview" diff --git a/lib/philomena_web/views/markdown_view.ex b/lib/philomena_web/views/markdown_view.ex index 95996133..3ecae0ac 100644 --- a/lib/philomena_web/views/markdown_view.ex +++ b/lib/philomena_web/views/markdown_view.ex @@ -5,6 +5,9 @@ defmodule PhilomenaWeb.MarkdownView do conn.assigns.current_user.anonymous_by_default end - def required?(%{assigns: %{required: false}}), do: nil + def required?(required) when required == false, do: nil def required?(_), do: true + + def add_classes(base_classes, new_classes) when is_binary(new_classes), do: "#{base_classes} #{new_classes}" + def add_classes(base_classes, _), do: base_classes end