From 20fbec96d48263c57d48eaae56eabd570ca3af47 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Fri, 24 May 2019 20:14:13 +1200 Subject: [PATCH] Tidying up forms --- app/controllers/plantings_controller.rb | 2 +- app/views/gardens/_form.html.haml | 84 +++++++++---------------- app/views/harvests/_form.html.haml | 17 ++--- app/views/plantings/_form.html.haml | 4 +- app/views/posts/_form.html.haml | 32 +++++----- 5 files changed, 54 insertions(+), 85 deletions(-) diff --git a/app/controllers/plantings_controller.rb b/app/controllers/plantings_controller.rb index c71fb6a5d..54ef9563f 100644 --- a/app/controllers/plantings_controller.rb +++ b/app/controllers/plantings_controller.rb @@ -41,7 +41,7 @@ class PlantingsController < ApplicationController end def new - @planting = Planting.new(planted_at: Time.zone.today) + @planting = Planting.new(planted_at: Time.zone.today, owner: current_member ) @seed = Seed.find_by(slug: params[:seed_id]) if params[:seed_id] # using find_by_id here because it returns nil, unlike find diff --git a/app/views/gardens/_form.html.haml b/app/views/gardens/_form.html.haml index 3e14520d3..1f40366d8 100644 --- a/app/views/gardens/_form.html.haml +++ b/app/views/gardens/_form.html.haml @@ -1,11 +1,11 @@ .card.col-md-8.col-lg-7.mx-auto.float-none.white.z-depth-1.py-2.px-2 - .card-body + = bootstrap_form_for(@garden) do |f| - if content_for? :title - %h1.h2-responsive.text-center - %strong=yield :title - = required_field_help_text - - = form_for(@garden, html: { class: "form-horizontal", role: "form" }) do |f| + .card-header + %h1.h2-responsive.text-center + %strong=yield :title + .card-body + = required_field_help_text - if @garden.errors.any? #error_explanation %h2 @@ -15,55 +15,27 @@ - @garden.errors.full_messages.each do |msg| %li= msg - .form-group.required - = f.label :name, class: 'control-label col-md-2' - .col-md-8 - = f.text_field :name, class: 'form-control', maxlength: 255, required: "required" + = f.text_field :name, maxlength: 255, required: "required" + = f.text_area :description, rows: 6 - .form-group - = f.label :description, class: 'control-label col-md-2' - .col-md-8 - = f.text_area :description, rows: 6, class: 'form-control' - = render partial: 'shared/form_optional' + = f.text_field :location, + value: @garden.location || current_member.location, + class: 'form-control', maxlength: 255 + = render partial: 'shared/form_optional' + %span.help-block + = t('.location_helper') + - if current_member.location.blank? + = link_to "Set your location now.", edit_member_registration_path + - else + = link_to "Change your location.", edit_member_registration_path + .row + .col-3= f.number_field :area, class: 'input-small' + .col-3= f.select(:area_unit, Garden::AREA_UNITS_VALUES, { include_blank: false }) + .col-6= f.select(:garden_type_id, GardenType.all.order(:name).pluck(:name, :id), + selected: @garden.garden_type_id) - .form-group - = f.label :location, class: 'control-label col-md-2' - .col-md-8 - = f.text_field :location, - value: @garden.location || current_member.location, - class: 'form-control', maxlength: 255 - = render partial: 'shared/form_optional' - %span.help-block - = t('.location_helper') - - if current_member.location.blank? - = link_to "Set your location now.", edit_member_registration_path - - else - = link_to "Change your location.", edit_member_registration_path - - .form-group - = f.label :area, class: 'control-label col-md-2' - .col-md-2 - = f.number_field :area, class: 'input-small form-control' - = render partial: 'shared/form_optional' - .col-md-2 - = f.select(:area_unit, Garden::AREA_UNITS_VALUES, { include_blank: false }, class: 'form-control') - - .form-group - = f.label :garden_type, class: 'control-label col-md-2' - .col-md-2 - = collection_select(:garden, :garden_type_id, - GardenType.all.order(:name), - :id, :name, - selected: @garden.garden_type_id, - class: 'form-control') - - .form-group - = f.label :active, 'Active? ', class: 'control-label col-md-2' - .col-md-8 - = f.check_box :active - You can mark a garden as inactive if you no longer use it. Note: - this will mark all plantings in the garden as "finished". - - .form-group - .form-actions.col-md-offset-2.col-md-8 - = f.submit 'Save Garden', class: 'btn btn-primary' + = f.check_box :active, label: 'Active?' + You can mark a garden as inactive if you no longer use it. Note: + this will mark all plantings in the garden as "finished". + .card-footer + .text-right= f.submit 'Save Garden' diff --git a/app/views/harvests/_form.html.haml b/app/views/harvests/_form.html.haml index 99e27afdb..53d1b9702 100644 --- a/app/views/harvests/_form.html.haml +++ b/app/views/harvests/_form.html.haml @@ -1,12 +1,13 @@ .card.col-md-8.col-lg-7.mx-auto.float-none.white.z-depth-1.py-2.px-2 - .card-header - - if content_for? :title - %h1.h2-responsive.text-center - %strong=yield :title - .card-body - = required_field_help_text - = bootstrap_form_for(@harvest) do |f| + = bootstrap_form_for(@harvest) do |f| + .card-header + - if content_for? :title + %h1.h2-responsive.text-center + = harvest_icon + %strong=yield :title + .card-body + = required_field_help_text - if @harvest.errors.any? #error_explanation %h2 #{pluralize(@harvest.errors.size, "error")} prohibited this harvest from being saved:" @@ -50,6 +51,6 @@ = f.select(:weight_unit, Harvest::WEIGHT_UNITS_VALUES, { include_blank: false }, class: 'form-control') = f.text_area :description, rows: 6, label: 'Notes' - + .card-footer .text-right= f.submit 'Save' diff --git a/app/views/plantings/_form.html.haml b/app/views/plantings/_form.html.haml index 8aa5da484..0be7dd0dd 100644 --- a/app/views/plantings/_form.html.haml +++ b/app/views/plantings/_form.html.haml @@ -28,14 +28,14 @@ .row .col-md-8 = f.collection_radio_buttons(:garden_id, - @planting.owner.gardens.active.order_by_name, :id, :name, required: true, + @planting.owner.gardens.active.order_by_name, + :id, :name, required: true, label: 'Where did you plant it?') = link_to "Add a garden.", new_garden_path .col-md-4 = f.text_field :planted_at, value: @planting.planted_at ? @planting.planted_at.to_s(:ymd) : '', class: 'add-datepicker', label: 'When?' - -# = render partial: 'shared/form_optional' .row .col-md-4= f.select(:planted_from, Planting::PLANTED_FROM_VALUES, { include_blank: '' }, label: 'Planted from') diff --git a/app/views/posts/_form.html.haml b/app/views/posts/_form.html.haml index aa115588a..3a70c5b65 100644 --- a/app/views/posts/_form.html.haml +++ b/app/views/posts/_form.html.haml @@ -1,9 +1,9 @@ .card.col-md-8.col-lg-7.mx-auto.float-none.white.z-depth-1.py-2.px-2 - .card-body - - if content_for? :title - %h1.h2-responsive.text-center - %strong=yield :title - = form_for(@post, html: { role: "form" }) do |f| + = bootstrap_form_for(@post) do |f| + .card-body + - if content_for? :title + %h1.h2-responsive.text-center + %strong=yield :title - if @post.errors.any? #error_explanation %h2 @@ -13,18 +13,14 @@ - @post.errors.full_messages.each do |msg| %li= msg - .form-group - = label_tag :post, "Subject", class: 'control-label' - = f.text_field :subject, class: 'form-control', autofocus: 'autofocus', maxlength: 255 + = f.text_field :subject, autofocus: 'autofocus', maxlength: 255 - .form-group - - if @post.forum || @forum - = label_tag :body, "What's up?", class: 'control-label' - - else - = label_tag :body, "What's going on in your food garden?" - = f.text_area :body, rows: 12, class: 'form-control' - %span.help-block - = render partial: "shared/markdown_help" + - if @post.forum || @forum + = label_tag :body, "What's up?" + - else + = label_tag :body, "What's going on in your food garden?" + = f.text_area :body, rows: 12 + %span.help-block= render partial: "shared/markdown_help" - if @post.forum || @forum - forum = @post.forum || @forum @@ -33,5 +29,5 @@ = link_to forum.name, forum .field = f.hidden_field :forum_id, value: forum.id - - = f.submit "Post", class: 'btn btn-primary' + .card-footer + .text-right= f.submit "Post", class: 'btn btn-primary'