client_side_validations 13.1.0 → 14.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 38a83d913f4fe8deb8803b0f6e63934794c1cf891f8078b0dfdcef0c80e926a9
4
- data.tar.gz: 501a06876e49ca0a667e3c151c37af549aa53f3240c41e63dc1a0bd176bf0111
3
+ metadata.gz: 862e0a65e6bd5db8f9c56423882eeb66b6523d9e7c87f74dfff1d9e419fa6dd4
4
+ data.tar.gz: 11cb6097f098d5eed2b1cda4a3d09675e8ea34c5fafd69f57faad5b406970c10
5
5
  SHA512:
6
- metadata.gz: 7446715f98d05f4d46b9d361a25ad3fa8ad0dffe390c6dbde0466a9b4b66ef76f00d76c8c9f9a1653479459adcae981bc8501feeecbc86d78f8456fac9716d2a
7
- data.tar.gz: eb0908f2eb8ec7d3bf2b501acb98df4c867bbd57c4ced7381faeef2a2aa2404eafbc6f6083205495cb1076029e31345e2740230c14795353849f09f498e53de0
6
+ metadata.gz: a2c615f902a308111b0343f0243a464eeb402904b2d60f4159b66314142f636bbfbd8c940ac507b4503c47a4aac41c912f8e021ef10050c0ddb4d9c49f27e3fa
7
+ data.tar.gz: '0377298e6937330f6cc7c3347f2f5599dc6309779ccb430ae87a213dbac8807c21920c9905824ea9b672a661240a3e671225141a7b8ab57f2b3469d9b7a86013'
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 14.0.0 / 2019-04-23
4
+
5
+ * [FEATURE] Add form_with support
6
+ * [ENHANCEMENT] Test against jQuery 3.4.0 by default
7
+
3
8
  ## 13.1.0 / 2019-03-14
4
9
 
5
10
  * [FEATURE] Add Rails 6.0.0.beta3 compatibility
data/README.md CHANGED
@@ -99,6 +99,16 @@ In your `FormBuilder` you only need to enable validations:
99
99
 
100
100
  That should be enough to get you going.
101
101
 
102
+ Starting from version 14.0, ClientSideValidations also supports `form_with`
103
+ when used together with Rails >= 5.1. The syntax is the same as `form_for`:
104
+
105
+ ```erb
106
+ <%= form_with model: @user, validate: true do |f| %>
107
+ ...
108
+ ```
109
+
110
+ **Note:** ClientSideValidations requires `id` attributes on form fields to
111
+ work, so it will force `form_with` to generate ids.
102
112
 
103
113
  ## Conditional Validators ##
104
114
 
@@ -258,7 +268,7 @@ Please view the code in `rails.validations.js` to see how the existing `add` and
258
268
  ### Local Validators ###
259
269
  Client Side Validations supports the use of custom validators. The following is an example for creating a custom validator that validates the format of email addresses.
260
270
 
261
- Let's say you have several models that all have email fields and you are validating the format of that email address on each one. This is a common validation and could probably benefit from a custom validator. We're going to put the validator into `app/validators/email_validator.rb`
271
+ Let's say you have several models that all have email fields and you are validating the format of that email address on each one. This is a common validation and could probably benefit from a custom validator. We're going to put the validator into `config/initializers/email_validator.rb`
262
272
 
263
273
  ```ruby
264
274
  class EmailValidator < ActiveModel::EachValidator
@@ -277,6 +287,9 @@ module ActiveModel::Validations::HelperMethods
277
287
  end
278
288
  ```
279
289
 
290
+ Heads-up!: Put custom initializers in `config/initializers`, otherwise named validator helpers will not
291
+ be available and migrations will not work.
292
+
280
293
  Next we need to add the error message to the Rails i18n file `config/locales/en.yml`
281
294
 
282
295
  ```yaml
@@ -9,6 +9,11 @@ end
9
9
 
10
10
  require 'client_side_validations/core_ext'
11
11
  require 'client_side_validations/action_view/form_helper'
12
+
13
+ if ActionView::Helpers::FormHelper.method_defined?(:form_with)
14
+ require 'client_side_validations/action_view/form_with_helper'
15
+ end
16
+
12
17
  require 'client_side_validations/action_view/form_builder'
13
18
 
14
19
  ActionView::Base.send(:include, ClientSideValidations::ActionView::Helpers::FormHelper)
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ClientSideValidations
4
+ module ActionView
5
+ module Helpers
6
+ module FormHelper
7
+ def form_with(model: nil, scope: nil, url: nil, format: nil, **options, &block)
8
+ return super unless options[:validate]
9
+
10
+ options[:allow_method_names_outside_object] = true
11
+ options[:skip_default_ids] = false
12
+
13
+ url, model, scope = check_model(url, model, format, scope) if model
14
+
15
+ if block_given?
16
+ form_tag_with_validators scope, model, options, url, &block
17
+ else
18
+ html_options = html_options_for_form_with(url, model, options)
19
+ form_tag_html(html_options)
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def check_model(url, model, format, scope)
26
+ url ||= polymorphic_path(model, format: format)
27
+
28
+ model = model.last if model.is_a?(Array)
29
+ scope ||= model_name_from_record_or_class(model).param_key
30
+
31
+ [url, model, scope]
32
+ end
33
+
34
+ def form_tag_with_validators(scope, model, options, url)
35
+ @validators = {}
36
+
37
+ builder = instantiate_builder(scope, model, options)
38
+ output = capture(builder, &Proc.new)
39
+ options[:multipart] ||= builder.multipart?
40
+
41
+ build_bound_validators! options
42
+
43
+ html_options = html_options_for_form_with(url, model, options)
44
+
45
+ if model
46
+ html_options[:novalidate] ||= 'novalidate'
47
+ apply_csv_html_options! html_options, options, builder
48
+ end
49
+
50
+ form_tag_with_body(html_options, output)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ClientSideValidations
4
- VERSION = '13.1.0'.freeze
4
+ VERSION = '14.0.0'.freeze
5
5
  end
@@ -1,6 +1,6 @@
1
1
 
2
2
  /*!
3
- * Client Side Validations - v13.1.0 (https://github.com/DavyJonesLocker/client_side_validations)
3
+ * Client Side Validations - v14.0.0 (https://github.com/DavyJonesLocker/client_side_validations)
4
4
  * Copyright (c) 2019 Geremia Taglialatela, Brian Cardarella
5
5
  * Licensed under MIT (http://opensource.org/licenses/mit-license.php)
6
6
  */
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: client_side_validations
3
3
  version: !ruby/object:Gem::Version
4
- version: 13.1.0
4
+ version: 14.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geremia Taglialatela
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-03-14 00:00:00.000000000 Z
12
+ date: 2019-04-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -169,14 +169,14 @@ dependencies:
169
169
  requirements:
170
170
  - - "~>"
171
171
  - !ruby/object:Gem::Version
172
- version: 0.65.0
172
+ version: 0.67.2
173
173
  type: :development
174
174
  prerelease: false
175
175
  version_requirements: !ruby/object:Gem::Requirement
176
176
  requirements:
177
177
  - - "~>"
178
178
  - !ruby/object:Gem::Version
179
- version: 0.65.0
179
+ version: 0.67.2
180
180
  - !ruby/object:Gem::Dependency
181
181
  name: simplecov
182
182
  requirement: !ruby/object:Gem::Requirement
@@ -197,14 +197,14 @@ dependencies:
197
197
  requirements:
198
198
  - - "~>"
199
199
  - !ruby/object:Gem::Version
200
- version: 1.3.6
200
+ version: '1.3'
201
201
  type: :development
202
202
  prerelease: false
203
203
  version_requirements: !ruby/object:Gem::Requirement
204
204
  requirements:
205
205
  - - "~>"
206
206
  - !ruby/object:Gem::Version
207
- version: 1.3.6
207
+ version: '1.3'
208
208
  - !ruby/object:Gem::Dependency
209
209
  name: coffee-script
210
210
  requirement: !ruby/object:Gem::Requirement
@@ -276,6 +276,7 @@ files:
276
276
  - lib/client_side_validations/action_view.rb
277
277
  - lib/client_side_validations/action_view/form_builder.rb
278
278
  - lib/client_side_validations/action_view/form_helper.rb
279
+ - lib/client_side_validations/action_view/form_with_helper.rb
279
280
  - lib/client_side_validations/active_model.rb
280
281
  - lib/client_side_validations/active_model/absence.rb
281
282
  - lib/client_side_validations/active_model/acceptance.rb