formwandler 0.0.1 → 0.1.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/field.rb +1 -1
- data/lib/formwandler/form.rb +13 -5
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31045e2505c0ef7d1dd3a1f8d104414472f993a3
|
4
|
+
data.tar.gz: 4832949e084649a57080971ce6b99b9543b0f771
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcaa3f9f9759283537aad421362e684d55d7c9f8ea3571d935450950887adb3ed6d7ae2553814f06e05241b64f7164c190572491eb5892e3434bc666dbbdae52
|
7
|
+
data.tar.gz: 2556aebc204214bd56ad1d7a2a3fa91413011d10620b4d63d678ca42f21498a74cc59d98d96e79bee736302f6c698dd078718b89f260a68bc013ceeaa0f30d52
|
data/lib/formwandler/field.rb
CHANGED
data/lib/formwandler/form.rb
CHANGED
@@ -46,7 +46,7 @@ module Formwandler
|
|
46
46
|
attr_reader :model_save_order
|
47
47
|
end
|
48
48
|
|
49
|
-
attr_reader :
|
49
|
+
attr_reader :models, :current_user
|
50
50
|
|
51
51
|
def initialize(models: {}, current_user: nil)
|
52
52
|
@models = models.symbolize_keys
|
@@ -66,11 +66,19 @@ module Formwandler
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def field(name)
|
69
|
-
fields.fetch(name)
|
69
|
+
@fields.fetch(name)
|
70
|
+
end
|
71
|
+
|
72
|
+
def fields(*names)
|
73
|
+
if names.any?
|
74
|
+
@fields.fetch_values(*names)
|
75
|
+
else
|
76
|
+
@fields.values
|
77
|
+
end
|
70
78
|
end
|
71
79
|
|
72
80
|
def fields_for_model(model)
|
73
|
-
fields.
|
81
|
+
fields.select { |field| field.model == model }
|
74
82
|
end
|
75
83
|
|
76
84
|
def models_valid?
|
@@ -103,7 +111,7 @@ module Formwandler
|
|
103
111
|
end
|
104
112
|
|
105
113
|
def assign_defaults
|
106
|
-
fields.
|
114
|
+
fields.each do |field|
|
107
115
|
next unless field.default?
|
108
116
|
send("#{field.name}=", field.default) if send(field.name).nil?
|
109
117
|
end
|
@@ -120,7 +128,7 @@ module Formwandler
|
|
120
128
|
end
|
121
129
|
|
122
130
|
def permitted_params(params)
|
123
|
-
visible_fields = fields.
|
131
|
+
visible_fields = fields.reject(&:hidden?).map(&:name)
|
124
132
|
delocalizations = fields.transform_values(&:delocalize).compact
|
125
133
|
params = ActionController::Parameters.new(params) if params.is_a?(Hash)
|
126
134
|
params.require(model_name.param_key).permit(*visible_fields).delocalize(delocalizations)
|
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.0
|
4
|
+
version: 0.1.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-09-
|
11
|
+
date: 2017-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '5.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
description: Create form objects for multiple models, dynamically mark fields as hidden
|
28
42
|
or disabled and even hide select options dynamically
|
29
43
|
email: sbilharz@heilmannsoftware.de
|