formwandler 0.4.5 → 0.5.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
- SHA1:
3
- metadata.gz: 86dd200d3680f5f036bad6b03946529f2c5cf8a5
4
- data.tar.gz: d7cc2a2a19d99501d1332964d178e7b8087fb402
2
+ SHA256:
3
+ metadata.gz: 4d04197f5a3301a80069f8b0200228445e13ed4d0acfe967db3785d2a62197b8
4
+ data.tar.gz: 00e39bc2876b1aa9e782a28d4dd61b898b465618cd3bbc3e7a2332f0c3d6f3ac
5
5
  SHA512:
6
- metadata.gz: 21035fb8ff9c567e490970b9eef801583666c294dc3963dbf4d77a2425138d0a76648861884564f52a7d8ba436215f05fc81c132b48ad726d676e3a1bde363cd
7
- data.tar.gz: 14370dfa22aee456eecb4cd953fc8374d5d70f4e19a947c1d394358a8c31f9fa81886b43fb77b3dd47ed4c93070620b66fb332afbd598f6b9021fa6b0bc7521a
6
+ metadata.gz: 102eb373dc65dc92b07fb6f495bd265f72713c4a8193628911dd5299a083fc4e2b2da8fa5d6286a2ead2acf097c3a08a9c63be7c0e86ea60e1a69eaab217b5f7
7
+ data.tar.gz: 2e049c3cc06cc1e55dd7411e716ab87a15ef179ed16704700912e42bd7e75d6d8d31a6aadf60f4c9b617e10477f163a3457ae4441ef9d53a4c36d06ca96e4a43
@@ -56,6 +56,10 @@ module Formwandler
56
56
  _evaluate_field_definition_value(:delocalize)
57
57
  end
58
58
 
59
+ def array?
60
+ field_definition.array
61
+ end
62
+
59
63
  private
60
64
 
61
65
  def transform_value(value, transformation)
@@ -4,9 +4,9 @@ require_relative 'field_value_transformer'
4
4
 
5
5
  module Formwandler
6
6
  class FieldDefinition
7
- attr_reader :name, :hidden, :disabled, :default, :delocalize, :model, :source, :options
7
+ attr_reader :name, :hidden, :disabled, :default, :delocalize, :model, :source, :options, :array
8
8
 
9
- def initialize(name, hidden: false, disabled: false, default: nil, delocalize: nil, model: nil, source: nil, options: nil)
9
+ def initialize(name, hidden: false, disabled: false, default: nil, delocalize: nil, model: nil, source: nil, options: nil, array: false)
10
10
  @name = name
11
11
  @hidden = hidden
12
12
  @disabled = disabled
@@ -15,6 +15,7 @@ module Formwandler
15
15
  @model = model
16
16
  @source = source || name
17
17
  @options = options
18
+ @array = array
18
19
  end
19
20
 
20
21
  def hide_option(name, value = true)
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative 'field_definition'
4
4
  require_relative 'field'
5
+ require 'delocalize'
5
6
 
6
7
  module Formwandler
7
8
  class Form
@@ -95,7 +96,9 @@ module Formwandler
95
96
 
96
97
  def submit
97
98
  if valid? && models_valid?
98
- save_models!
99
+ ActiveRecord::Base.transaction do
100
+ save_models!
101
+ end
99
102
  load_results
100
103
  else
101
104
  false
@@ -134,10 +137,15 @@ module Formwandler
134
137
  end
135
138
 
136
139
  def permitted_params
137
- visible_fields = fields.reject(&:hidden?).map(&:name)
138
140
  controller.params.require(model_name.param_key).permit(*visible_fields).delocalize(delocalizations)
139
141
  end
140
142
 
143
+ def visible_fields
144
+ fields.reject(&:hidden?).map do |field|
145
+ field.array? ? {field.name => []} : field.name
146
+ end
147
+ end
148
+
141
149
  def delocalizations
142
150
  fields.reduce({}) do |memo, field|
143
151
  memo[field.name] = field.delocalize
@@ -1,3 +1,3 @@
1
1
  module Formwandler
2
- VERSION = '0.4.5'
2
+ VERSION = '0.5.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formwandler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Bilharz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-01 00:00:00.000000000 Z
11
+ date: 2018-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -143,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  version: '0'
144
144
  requirements: []
145
145
  rubyforge_project:
146
- rubygems_version: 2.6.13
146
+ rubygems_version: 2.7.6
147
147
  signing_key:
148
148
  specification_version: 4
149
149
  summary: Form objects for rails