hungryform 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/hungryform/elements/base/element.rb +6 -1
- data/lib/hungryform/form.rb +9 -3
- data/lib/hungryform/version.rb +1 -1
- data/spec/form_spec.rb +22 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c55e397d5568ee783aa7a4c10579676ed50314bf
|
4
|
+
data.tar.gz: 23e0adea07adeaa6b2d3d613a48b32a79402bf7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 883d982d48448c144de2d9e6dcbbe97db6f49e59b4e97372031cbacaa8a19e16bfea8e20b2f9276e61d9496ac49a7939087bdfb2b1d79e34c07ce92b394c9366
|
7
|
+
data.tar.gz: aafb593254ac8fd69158b9990bd2d2bac90a2afc5dbf56714a0fda95fa8d4dd746bb124564600b94cd14db3fe21b3e1c74f6b45404a7f8d758b0e3c749639c4d
|
@@ -11,7 +11,7 @@ module HungryForm
|
|
11
11
|
hashable :visible, :dependency, :name, :label
|
12
12
|
|
13
13
|
def initialize(name, parent, resolver, attributes = {})
|
14
|
-
@attributes =
|
14
|
+
@attributes = configuration.dup
|
15
15
|
@attributes.merge!(attributes)
|
16
16
|
|
17
17
|
@placeholders ||= {}
|
@@ -42,6 +42,11 @@ module HungryForm
|
|
42
42
|
def dependency_json
|
43
43
|
JSON.generate(dependency) if dependency
|
44
44
|
end
|
45
|
+
|
46
|
+
# Configuration params specific to the element
|
47
|
+
def configuration
|
48
|
+
HungryForm.configuration.send(self.class.name.demodulize.underscore)
|
49
|
+
end
|
45
50
|
end
|
46
51
|
end
|
47
52
|
end
|
data/lib/hungryform/form.rb
CHANGED
@@ -52,7 +52,7 @@ module HungryForm
|
|
52
52
|
@current_page ||= pages.first
|
53
53
|
end
|
54
54
|
|
55
|
-
# Create a
|
55
|
+
# Create a new page
|
56
56
|
def page(name, attributes = {}, &block)
|
57
57
|
page = Elements::Page.new(name, nil, @resolver, attributes, &block)
|
58
58
|
pages << page if page.visible?
|
@@ -60,7 +60,7 @@ module HungryForm
|
|
60
60
|
|
61
61
|
# Entire form validation. Loops through the form pages and
|
62
62
|
# validates each page individually.
|
63
|
-
def
|
63
|
+
def validate
|
64
64
|
is_valid = true
|
65
65
|
|
66
66
|
pages.each do |page|
|
@@ -71,8 +71,12 @@ module HungryForm
|
|
71
71
|
is_valid
|
72
72
|
end
|
73
73
|
|
74
|
+
def valid?
|
75
|
+
validate
|
76
|
+
end
|
77
|
+
|
74
78
|
def invalid?
|
75
|
-
!
|
79
|
+
!validate
|
76
80
|
end
|
77
81
|
|
78
82
|
# Get all the elements the form consists of
|
@@ -101,12 +105,14 @@ module HungryForm
|
|
101
105
|
end
|
102
106
|
end
|
103
107
|
|
108
|
+
# Get the next page of the form
|
104
109
|
def next_page
|
105
110
|
pages.each_cons(2) do |page, next_page|
|
106
111
|
return next_page if page == current_page
|
107
112
|
end
|
108
113
|
end
|
109
114
|
|
115
|
+
# Get the previous page of the form
|
110
116
|
def prev_page
|
111
117
|
pages.each_cons(2) do |prev_page, page|
|
112
118
|
return prev_page if page == current_page
|
data/lib/hungryform/version.rb
CHANGED
data/spec/form_spec.rb
CHANGED
@@ -86,6 +86,17 @@ describe HungryForm do
|
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
|
+
describe "#validate" do
|
90
|
+
it "should be valid" do
|
91
|
+
expect(subject.valid?).to eq true
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should be invalid" do
|
95
|
+
options[:params]["first_first_name"] = ''
|
96
|
+
expect(subject.valid?).to eq false
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
89
100
|
describe "#valid?" do
|
90
101
|
it "should be valid" do
|
91
102
|
expect(subject.valid?).to eq true
|
@@ -97,6 +108,17 @@ describe HungryForm do
|
|
97
108
|
end
|
98
109
|
end
|
99
110
|
|
111
|
+
describe "#invalid?" do
|
112
|
+
it "should not be invalid" do
|
113
|
+
expect(subject.invalid?).to eq false
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should be invalid" do
|
117
|
+
options[:params]["first_first_name"] = ''
|
118
|
+
expect(subject.invalid?).to eq true
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
100
122
|
describe "#next_page" do
|
101
123
|
it "should return the next page" do
|
102
124
|
options[:params][:page] = "first"
|