From ddd4d6050ac5f564ef1ccae397f0c1514a7de157 Mon Sep 17 00:00:00 2001 From: Geremia Taglialatela Date: Fri, 1 May 2020 12:29:12 +0200 Subject: [PATCH] Playground for CSV 784 Ref: DavyJonesLocker/client_side_validations#784 --- Gemfile | 2 +- Gemfile.lock | 15 ++++++++++----- app/assets/javascripts/application.js | 1 + app/models/box.rb | 5 +++++ app/views/boxes/_form.html.erb | 9 +++++---- app/views/boxes/_simple_form.html.erb | 24 ++++++++++++++++++++++++ app/views/boxes/new.html.erb | 2 ++ app/views/pages/home.html.erb | 2 ++ 8 files changed, 50 insertions(+), 10 deletions(-) create mode 100644 app/views/boxes/_simple_form.html.erb diff --git a/Gemfile b/Gemfile index d52ea57..00ffdfe 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } ruby '2.7.1' gem 'jquery-rails', '~> 4.3' -gem 'client_side_validations', '~> 16.2.0' +gem 'client_side_validations', github: 'MichalRemis/client_side_validations', branch: 'SupportDateTimeSelects' # '~> 16.2.0' gem 'client_side_validations-simple_form', '~> 10.1.0' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' diff --git a/Gemfile.lock b/Gemfile.lock index a36df80..ad9b420 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,12 @@ +GIT + remote: https://github.com/MichalRemis/client_side_validations.git + revision: 5fa9a94829831b8714a5458431f54d992f597d9b + branch: SupportDateTimeSelects + specs: + client_side_validations (16.2.0) + js_regex (~> 3.1) + rails (>= 5.0.0.1, < 6.1) + GEM remote: https://rubygems.org/ specs: @@ -62,10 +71,6 @@ GEM builder (3.2.4) byebug (11.1.3) character_set (1.4.0) - client_side_validations (16.2.0) - jquery-rails (~> 4.3) - js_regex (~> 3.1) - rails (>= 5.0.0.1, < 6.1) client_side_validations-simple_form (10.1.0) client_side_validations (>= 15.0, < 17.0) simple_form (~> 5.0) @@ -200,7 +205,7 @@ PLATFORMS DEPENDENCIES bootsnap (>= 1.4.2) byebug - client_side_validations (~> 16.2.0) + client_side_validations! client_side_validations-simple_form (~> 10.1.0) jbuilder (~> 2.7) jquery-rails (~> 4.3) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index aff49c7..62b4c75 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -1,2 +1,3 @@ //= require jquery //= require rails.validations +//= require rails.validations.simple_form diff --git a/app/models/box.rb b/app/models/box.rb index 533e22a..f4af813 100644 --- a/app/models/box.rb +++ b/app/models/box.rb @@ -1,2 +1,7 @@ class Box < ApplicationRecord + validates :name, presence: true + validates :description, presence: true + validates :a_date, presence: true + validates :a_datetime, presence: true + validates :a_time, presence: true end diff --git a/app/views/boxes/_form.html.erb b/app/views/boxes/_form.html.erb index cb05898..06c75a6 100644 --- a/app/views/boxes/_form.html.erb +++ b/app/views/boxes/_form.html.erb @@ -1,4 +1,5 @@ -<%= form_with(model: box, local: true) do |form| %> +

Test CSV 784

+<%= form_with(model: box, local: true, validate: true) do |form| %> <% if box.errors.any? %>

<%= pluralize(box.errors.count, "error") %> prohibited this box from being saved:

@@ -23,17 +24,17 @@
<%= form.label :a_date %> - <%= form.date_select :a_date %> + <%= form.date_select :a_date, prompt: true %>
<%= form.label :a_datetime %> - <%= form.datetime_select :a_datetime %> + <%= form.datetime_select :a_datetime, prompt: true %>
<%= form.label :a_time %> - <%= form.time_select :a_time %> + <%= form.time_select :a_time, prompt: true %>
diff --git a/app/views/boxes/_simple_form.html.erb b/app/views/boxes/_simple_form.html.erb new file mode 100644 index 0000000..d8d79c6 --- /dev/null +++ b/app/views/boxes/_simple_form.html.erb @@ -0,0 +1,24 @@ +

Test CSV 784

+<%= simple_form_for(box, validate: true) do |form| %> + <% if box.errors.any? %> +
+

<%= pluralize(box.errors.count, "error") %> prohibited this box from being saved:

+ +
    + <% box.errors.full_messages.each do |message| %> +
  • <%= message %>
  • + <% end %> +
+
+ <% end %> + + <%= form.input :name %> + <%= form.input :description %> + <%= form.input :a_date, prompt: true %> + <%= form.input :a_datetime, prompt: true %> + <%= form.input :a_time, prompt: true %> + +
+ <%= form.submit %> +
+<% end %> diff --git a/app/views/boxes/new.html.erb b/app/views/boxes/new.html.erb index 0aeb5e7..634f2d1 100644 --- a/app/views/boxes/new.html.erb +++ b/app/views/boxes/new.html.erb @@ -1,5 +1,7 @@

New Box

+ + <%= render 'form', box: @box %> <%= link_to 'Back', boxes_path %> diff --git a/app/views/pages/home.html.erb b/app/views/pages/home.html.erb index 2e7985d..1c79255 100644 --- a/app/views/pages/home.html.erb +++ b/app/views/pages/home.html.erb @@ -1 +1,3 @@

Client Side Validations Playground

+ +<%= link_to 'CSV 784', new_box_path %>