formwandler 0.6.0 → 0.7.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: 8a45d189660c8aace9e7271c8d9dc110962a75954c538b8e0ffc29c882f0cde4
4
- data.tar.gz: 85d1558cfd2507a7bbf57cb4c21f5c41f205df3230a49e408d4333e2c9fa40ed
3
+ metadata.gz: 2baf488a4d1a35a90e7a53d588c8d843fccab4cc8ce9de5cda36920d4d9b22aa
4
+ data.tar.gz: a00ac15d3663ea1e7c313170681bd3d949c30024862a98c44afc891e2d611ca1
5
5
  SHA512:
6
- metadata.gz: 136d046b2a96878ecdc22c39a8e1c4ff400a8e211d063397ad8e1d38aed2ddcf30e342e50c21292f6fbfbbefc809569be90fcd13c897d0c9bb5b05b1bdf280bc
7
- data.tar.gz: f9fdf3e938ec7476755097233005a173c8b6ef68f4d8ec2ff24cd33edc1b300885f9a36392a09ba86de0516d38c7caa102bf2381cbd96b98886ad145906ca2f8
6
+ metadata.gz: 4d91c842de66da094997e6e270349af7fcc76ef66ab32a597fd444e857ee97b3990c0ab3e99539534e8b43dc1478573a41f8c707533805b63ea1c704b0f87dc1
7
+ data.tar.gz: 297b12e919ba35ac50d90ae3e73b8d87ff211cdc401bbdcc02cf20457502a63efed0b18b871f165fabc278f3e21b4b231075de9ba87ea316302f68dd9390e45b
@@ -83,22 +83,14 @@ module Formwandler
83
83
  fields.select { |field| field.model == model }
84
84
  end
85
85
 
86
- def models_valid?
87
- all_valid = true
88
- models.each do |name, model|
89
- all_valid = false if model.invalid?
90
- next if model.valid?
91
- fields_for_model(name).each do |field|
92
- model.errors[field.source].each do |error_message|
93
- errors.add(field.name, error_message)
94
- end
95
- end
96
- end
97
- all_valid
86
+ def valid?
87
+ form_valid = super
88
+ models_valid = models_valid?
89
+ form_valid && models_valid
98
90
  end
99
91
 
100
92
  def submit
101
- if valid? && models_valid?
93
+ if valid?
102
94
  ActiveRecord::Base.transaction do
103
95
  save_models!
104
96
  end
@@ -125,6 +117,20 @@ module Formwandler
125
117
  assign_attributes permitted_params
126
118
  end
127
119
 
120
+ def models_valid?
121
+ all_valid = true
122
+ models.each do |name, model|
123
+ all_valid = false if model.invalid?
124
+ next if model.valid?
125
+ fields_for_model(name).each do |field|
126
+ model.errors[field.source].each do |error_message|
127
+ errors.add(field.name, error_message)
128
+ end
129
+ end
130
+ end
131
+ all_valid
132
+ end
133
+
128
134
  def save_models!
129
135
  models.sort_by do |(name, _model)|
130
136
  self.class.model_save_order&.index(name) || self.class.model_save_order&.size
@@ -140,11 +146,11 @@ module Formwandler
140
146
  end
141
147
 
142
148
  def permitted_params
143
- controller.params.require(model_name.param_key).permit(*visible_fields).delocalize(delocalizations)
149
+ controller.params.require(model_name.param_key).permit(*permitted_fields).delocalize(delocalizations)
144
150
  end
145
151
 
146
- def visible_fields
147
- fields.reject(&:hidden?).map do |field|
152
+ def permitted_fields
153
+ fields.reject(&:disabled?).map do |field|
148
154
  field.array? ? {field.name => []} : field.name
149
155
  end
150
156
  end
@@ -1,3 +1,3 @@
1
1
  module Formwandler
2
- VERSION = '0.6.0'
2
+ VERSION = '0.7.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.6.0
4
+ version: 0.7.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: 2018-07-09 00:00:00.000000000 Z
11
+ date: 2018-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails