[Forms] Add displaying dropdowns as button selects

The first user of this is creating user feedback,  where you have 3 buttons
Also default to negative feedback when linking to create on user pages
This commit is contained in:
Earlopain 2022-07-13 23:35:36 +02:00
parent f7e6985c82
commit 619754283b
No known key found for this signature in database
GPG Key ID: 6CFB948E15246897
4 changed files with 31 additions and 2 deletions

View File

@ -4,5 +4,14 @@ class CustomFormBuilder < SimpleForm::FormBuilder
super
end
def button_select(attribute_name, values, **args)
html = collection_radio_buttons(attribute_name, values, :first, :last)
label = args[:label] || attribute_name.to_s.titleize
%(<div class="collection-radio-buttons input">
<label>#{label}</label>
#{html}
</div>).html_safe
end
include FormBuilderCommon
end

View File

@ -43,6 +43,26 @@ form.simple_form {
}
}
}
div.collection-radio-buttons {
input {
display: none;
}
input + label {
@extend .button;
// Overwrite the themed color from the imported class, which has higher specificity
color: black !important;
background-color: white;
margin: 0 0.25rem 0.25rem 0;
font-weight: normal;
cursor: pointer;
}
input:checked + label {
@include themable { background-color: themed("color-button-active"); }
}
}
}
form.inline-form {

View File

@ -2,7 +2,7 @@
<% if user_feedback.new_record? %>
<%= f.input :user_name, label: "User", autocomplete: "user", input_html: { value: user_feedback.user.try(:name) } %>
<% end %>
<%= f.input :category, collection: ["positive", "neutral", "negative"], include_blank: false %>
<%= f.button_select :category, ["positive", "neutral", "negative"].map { |e| [e, e.titleize] } %>
<%= dtext_field "user_feedback", "body" %>
<%= f.button :submit, "Submit" %>
<% end %>

View File

@ -96,7 +96,7 @@
<%= presenter.feedbacks %>
<%= link_to("List", user_feedbacks_path(search: { user_id: @user.id })) %>
<% if CurrentUser.is_moderator? && @user.feedback.count.zero? %>
| <%= link_to("Create", new_user_feedback_path(user_feedback: { user_id: @user.id })) %>
| <%= link_to("Create", new_user_feedback_path(user_feedback: { user_id: @user.id, category: "neutral" })) %>
<% end %>
</span>