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 +4 -4
- data/lib/formwandler/form.rb +22 -16
- data/lib/formwandler/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2baf488a4d1a35a90e7a53d588c8d843fccab4cc8ce9de5cda36920d4d9b22aa
|
4
|
+
data.tar.gz: a00ac15d3663ea1e7c313170681bd3d949c30024862a98c44afc891e2d611ca1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d91c842de66da094997e6e270349af7fcc76ef66ab32a597fd444e857ee97b3990c0ab3e99539534e8b43dc1478573a41f8c707533805b63ea1c704b0f87dc1
|
7
|
+
data.tar.gz: 297b12e919ba35ac50d90ae3e73b8d87ff211cdc401bbdcc02cf20457502a63efed0b18b871f165fabc278f3e21b4b231075de9ba87ea316302f68dd9390e45b
|
data/lib/formwandler/form.rb
CHANGED
@@ -83,22 +83,14 @@ module Formwandler
|
|
83
83
|
fields.select { |field| field.model == model }
|
84
84
|
end
|
85
85
|
|
86
|
-
def
|
87
|
-
|
88
|
-
|
89
|
-
|
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?
|
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(*
|
149
|
+
controller.params.require(model_name.param_key).permit(*permitted_fields).delocalize(delocalizations)
|
144
150
|
end
|
145
151
|
|
146
|
-
def
|
147
|
-
fields.reject(&:
|
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
|
data/lib/formwandler/version.rb
CHANGED
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
|
+
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-
|
11
|
+
date: 2018-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|