caring_form 1.2.3
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 +7 -0
- data/.gitignore +19 -0
- data/.travis.yml +17 -0
- data/Appraisals +18 -0
- data/Gemfile +9 -0
- data/Guardfile +15 -0
- data/LICENSE +22 -0
- data/README.md +33 -0
- data/Rakefile +12 -0
- data/app/assets/javascripts/caring_form/form-observer.coffee +63 -0
- data/app/assets/javascripts/caring_form/main.coffee +15 -0
- data/app/assets/javascripts/caring_form/remote-validator.coffee +71 -0
- data/app/assets/javascripts/caring_form/rule-based-validator.coffee +37 -0
- data/app/assets/javascripts/caring_form/setup.coffee +5 -0
- data/app/assets/javascripts/caring_form/webshims-customization.coffee +25 -0
- data/app/assets/javascripts/caring_forms.js +7 -0
- data/caring_form.gemspec +31 -0
- data/gemfiles/rails_3_1.gemfile +8 -0
- data/gemfiles/rails_3_2.gemfile +8 -0
- data/gemfiles/rails_4.gemfile +7 -0
- data/gemfiles/rails_4_1.gemfile +8 -0
- data/lib/caring_form.rb +20 -0
- data/lib/caring_form/action_view_extensions/builder.rb +75 -0
- data/lib/caring_form/action_view_extensions/config.rb +4 -0
- data/lib/caring_form/action_view_extensions/flash_error_helper.rb +28 -0
- data/lib/caring_form/action_view_extensions/form_helper.rb +33 -0
- data/lib/caring_form/active_model/monkey_patching.rb +32 -0
- data/lib/caring_form/dsl.rb +91 -0
- data/lib/caring_form/engine.rb +4 -0
- data/lib/caring_form/field/base.rb +145 -0
- data/lib/caring_form/field/check_box.rb +23 -0
- data/lib/caring_form/field/check_boxes.rb +15 -0
- data/lib/caring_form/field/collection.rb +48 -0
- data/lib/caring_form/field/dummy.rb +30 -0
- data/lib/caring_form/field/email.rb +41 -0
- data/lib/caring_form/field/full_name.rb +40 -0
- data/lib/caring_form/field/looking_for.rb +37 -0
- data/lib/caring_form/field/metadata.rb +26 -0
- data/lib/caring_form/field/radio_buttons.rb +15 -0
- data/lib/caring_form/field/string.rb +13 -0
- data/lib/caring_form/field/submit.rb +83 -0
- data/lib/caring_form/field/tel.rb +37 -0
- data/lib/caring_form/field/text.rb +13 -0
- data/lib/caring_form/field/us_zip_code.rb +37 -0
- data/lib/caring_form/field_container.rb +126 -0
- data/lib/caring_form/form_builder.rb +51 -0
- data/lib/caring_form/model.rb +58 -0
- data/lib/caring_form/model/active_model.rb +11 -0
- data/lib/caring_form/model/active_record.rb +38 -0
- data/lib/caring_form/simple_form/initializer.rb +26 -0
- data/lib/caring_form/simple_form/monkey_patching.rb +51 -0
- data/lib/caring_form/tools/referee.rb +62 -0
- data/lib/caring_form/version.rb +3 -0
- data/lib/tasks/webshims.rake +7 -0
- data/spec/caring_form/action_view_extensions/flash_error_helper_spec.rb +50 -0
- data/spec/caring_form/action_view_extensions/form_helper_spec.rb +72 -0
- data/spec/caring_form/dsl_spec.rb +21 -0
- data/spec/caring_form/field/base_spec.rb +204 -0
- data/spec/caring_form/field/check_boxes_spec.rb +32 -0
- data/spec/caring_form/field/collection_spec.rb +28 -0
- data/spec/caring_form/field/radio_buttons_spec.rb +29 -0
- data/spec/caring_form/field/submit_spec.rb +57 -0
- data/spec/caring_form/field_container_spec.rb +85 -0
- data/spec/caring_form/form_builder_spec.rb +113 -0
- data/spec/caring_form/model_spec.rb +235 -0
- data/spec/caring_form/tools/referee_spec.rb +86 -0
- data/spec/spec_helper.rb +28 -0
- data/spec/support/nokogiri_matcher.rb +204 -0
- metadata +278 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'caring_form/field/check_boxes'
|
|
2
|
+
|
|
3
|
+
module CaringForm
|
|
4
|
+
module Field
|
|
5
|
+
class CheckBox < Collection
|
|
6
|
+
register :check_box
|
|
7
|
+
|
|
8
|
+
def apply_to_model(klass)
|
|
9
|
+
unless value.present?
|
|
10
|
+
raise ArgumentError, "check_box: missing mandatory :value parameter"
|
|
11
|
+
end
|
|
12
|
+
self.collection = [[value[:label], value[:checked]]]
|
|
13
|
+
super
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def input_properties(form, options = {})
|
|
17
|
+
super.tap do |req|
|
|
18
|
+
req[:as] = options.fetch(:as, :caring_check)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'caring_form/field/collection'
|
|
2
|
+
|
|
3
|
+
module CaringForm
|
|
4
|
+
module Field
|
|
5
|
+
class CheckBoxes < Collection
|
|
6
|
+
register :check_boxes
|
|
7
|
+
|
|
8
|
+
def input_properties(form, options = {})
|
|
9
|
+
super.tap do |req|
|
|
10
|
+
req[:as] = options.fetch(:as, :caring_check)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# TODO: keep this as an abstract class and create a different "drop_down" field that inherits from it
|
|
2
|
+
# TODO: make inclusion validation message configurable
|
|
3
|
+
require 'caring_form/field/base'
|
|
4
|
+
|
|
5
|
+
module CaringForm
|
|
6
|
+
module Field
|
|
7
|
+
class Collection < Base
|
|
8
|
+
register :collection
|
|
9
|
+
|
|
10
|
+
def simple_type
|
|
11
|
+
self.as || :select
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def apply_to_model(klass)
|
|
15
|
+
super
|
|
16
|
+
if (range = valid_values)
|
|
17
|
+
klass.send(:validates_inclusion_of, name, :allow_blank => true,
|
|
18
|
+
:in => range, :message => message)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def input_properties(form, options = {})
|
|
23
|
+
super.tap do |req|
|
|
24
|
+
req[:include_blank] = false
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def message
|
|
31
|
+
"This value is not valid"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def valid_values
|
|
35
|
+
return nil if collection.nil?
|
|
36
|
+
if collection.is_a?(Symbol)
|
|
37
|
+
return nil unless defined?(ActiveModel)
|
|
38
|
+
lambda { |model|
|
|
39
|
+
values = model.send(collection)
|
|
40
|
+
values.last.is_a?(Array) ? values.map(&:last) : values
|
|
41
|
+
}
|
|
42
|
+
else
|
|
43
|
+
collection.last.is_a?(Array) ? collection.map(&:last) : collection
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require 'caring_form/field/base'
|
|
2
|
+
|
|
3
|
+
module CaringForm
|
|
4
|
+
module Field
|
|
5
|
+
class Dummy < Base
|
|
6
|
+
register :dummy
|
|
7
|
+
|
|
8
|
+
def simple_type
|
|
9
|
+
:string
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def apply_to_model(klass)
|
|
13
|
+
klass.send(:attr_accessor, name)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def optional
|
|
17
|
+
true
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def input_properties(form, options = {})
|
|
21
|
+
super.tap do |req|
|
|
22
|
+
req[:wrapper_html][:class] = "form_add #{req[:wrapper_html][:class]}".strip
|
|
23
|
+
req[:wrapper_tag] = 'div'
|
|
24
|
+
# don't require the field on the client side, it's a dummy
|
|
25
|
+
req[:input_html][:required] = nil
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require 'caring_form/field/base'
|
|
2
|
+
|
|
3
|
+
module CaringForm
|
|
4
|
+
module Field
|
|
5
|
+
class Email < Base
|
|
6
|
+
register :email
|
|
7
|
+
|
|
8
|
+
def simple_type
|
|
9
|
+
:email
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def apply_to_model(klass)
|
|
13
|
+
super
|
|
14
|
+
klass.send(:validates_format_of, name, :allow_blank => true,
|
|
15
|
+
:with => regexp, :message => message, :multiline => true)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def input_properties(form, options = {})
|
|
19
|
+
super.tap do |req|
|
|
20
|
+
req[:input_html][:pattern] ||= regexp.source
|
|
21
|
+
req[:input_html][:title] ||= message
|
|
22
|
+
req[:input_html][:type] ||= 'email'
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
def default_label
|
|
29
|
+
"E-mail Address"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def regexp
|
|
33
|
+
/^([^@\s]+)@((?:[-a-z0-9A-Z]+\.)+[a-zA-Z]{2,})$/
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def message
|
|
37
|
+
"Enter a valid email address"
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
require 'caring_form/field/base'
|
|
2
|
+
|
|
3
|
+
module CaringForm
|
|
4
|
+
module Field
|
|
5
|
+
class FullName < Base
|
|
6
|
+
register :full_name
|
|
7
|
+
|
|
8
|
+
def simple_type
|
|
9
|
+
:string
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def apply_to_model(klass)
|
|
13
|
+
super
|
|
14
|
+
klass.send(:validates_format_of, name, :allow_blank => true,
|
|
15
|
+
:with => regexp, :message => message, :multiline => true)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def input_properties(form, options = {})
|
|
19
|
+
super.tap do |req|
|
|
20
|
+
req[:input_html][:pattern] ||= regexp.source
|
|
21
|
+
req[:input_html][:title] ||= message
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def default_label
|
|
28
|
+
"First and Last Name"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def regexp
|
|
32
|
+
/^\s*.*[a-zA-Z].*[a-zA-Z].*\s*$/
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def message
|
|
36
|
+
"Enter your first and last name"
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require 'caring_form/field/collection'
|
|
2
|
+
|
|
3
|
+
module CaringForm
|
|
4
|
+
module Field
|
|
5
|
+
class LookingFor < Collection
|
|
6
|
+
register :looking_for
|
|
7
|
+
|
|
8
|
+
def initialize(*args)
|
|
9
|
+
super
|
|
10
|
+
unless self.collection.present?
|
|
11
|
+
self.collection = options_collection
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def input_properties(form, options = {})
|
|
16
|
+
options[:prompt] = "-- Choose One --" if options.fetch(:prompt, prompt).nil?
|
|
17
|
+
super.tap do |req|
|
|
18
|
+
req[:input_html][:title] ||= message
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def default_label
|
|
25
|
+
"Looking for"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def options_collection
|
|
29
|
+
%w(Parent(s) Relative(s) Friend(s) Myself Spouse Patient/Client Job Other)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def message
|
|
33
|
+
"Tell us for whom you are seeking care"
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require 'caring_form/field/base'
|
|
2
|
+
|
|
3
|
+
module CaringForm
|
|
4
|
+
module Field
|
|
5
|
+
class Metadata < Base
|
|
6
|
+
register :metadata
|
|
7
|
+
|
|
8
|
+
def simple_type
|
|
9
|
+
:hidden
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def optional
|
|
13
|
+
true
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def input_properties(form, options = {})
|
|
17
|
+
req = {:as => :hidden, :input_html => {}, :label_html => {}}
|
|
18
|
+
if form.index_on.present?
|
|
19
|
+
req[:label_html][:index] = req[:input_html][:index] = form.index_on
|
|
20
|
+
end
|
|
21
|
+
req[:input_html][:name] = name if ancillary
|
|
22
|
+
req.deep_merge!(options)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'caring_form/field/collection'
|
|
2
|
+
|
|
3
|
+
module CaringForm
|
|
4
|
+
module Field
|
|
5
|
+
class RadioButtons < Collection
|
|
6
|
+
register :radio_buttons
|
|
7
|
+
|
|
8
|
+
def input_properties(form, options = {})
|
|
9
|
+
super.tap do |req|
|
|
10
|
+
req[:as] = options.fetch(:as, :caring_radio)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# TODO: remove deprecated :primary => true option
|
|
2
|
+
|
|
3
|
+
require 'caring_form/field/base'
|
|
4
|
+
|
|
5
|
+
module CaringForm
|
|
6
|
+
module Field
|
|
7
|
+
class Submit < Base
|
|
8
|
+
|
|
9
|
+
class Renderer
|
|
10
|
+
def initialize(field, form, template, options)
|
|
11
|
+
@field, @form, @template, @options = field, form, template, options
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def render
|
|
15
|
+
tag = @options[:wrapper_tag] || @field.wrapper_tag
|
|
16
|
+
html_options = @options[:wrapper_html] || @field.wrapper_html.dup
|
|
17
|
+
html_options[:class] = classes_from(html_options[:class], ['field'])
|
|
18
|
+
wrap_content = @options.fetch(:wrapper, @field.wrapper.nil? ? true : @field.wrapper)
|
|
19
|
+
if wrap_content
|
|
20
|
+
@template.content_tag(tag, render_button.html_safe, html_options)
|
|
21
|
+
else
|
|
22
|
+
render_button
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
def classes_for_tag(tag)
|
|
29
|
+
default_classes = tag.to_sym == :input ? ['input-width', 'trackable'] : []
|
|
30
|
+
default_classes + @field.properties.map { |property| "#{property}-button" }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def render_button
|
|
34
|
+
tag = @options[:input_tag] || @field.input_tag
|
|
35
|
+
@options[:input_html] ||= @field.input_html.dup
|
|
36
|
+
html_options = @options[:input_html] || @field.input_html.dup
|
|
37
|
+
label_value = @options[:label] || @field.label
|
|
38
|
+
classes = classes_for_tag(tag)
|
|
39
|
+
# for ascending compatibility, remove when :primary option converted in gg3 and caring
|
|
40
|
+
classes << 'primary-button' if @options.fetch(:primary, @field.primary)
|
|
41
|
+
html_options[:class] = classes_from(html_options[:class], classes)
|
|
42
|
+
html_options[:type] ||= 'submit'
|
|
43
|
+
|
|
44
|
+
if tag.to_sym == :input
|
|
45
|
+
@template.content_tag(:input, nil, html_options.merge(:name => 'commit', :value => label_value))
|
|
46
|
+
else
|
|
47
|
+
@template.content_tag(tag, label_value, html_options)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def classes_from(*sources)
|
|
52
|
+
sources.inject([]) do |classes, source|
|
|
53
|
+
next classes if source.nil?
|
|
54
|
+
items = source.kind_of?(Array) ? source : source.split
|
|
55
|
+
classes.push(*items)
|
|
56
|
+
end.uniq.join(' ')
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
register :submit
|
|
61
|
+
|
|
62
|
+
attr_accessor :properties
|
|
63
|
+
|
|
64
|
+
def initialize(*args)
|
|
65
|
+
super
|
|
66
|
+
self.primary ||= false
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def apply_to_model(klass)
|
|
70
|
+
raise "BUG ALERT: I shouldn't be called, I'm a submit"
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def render(form, builder, options = {})
|
|
74
|
+
options = normalize_options(form, options)
|
|
75
|
+
Renderer.new(self, form, builder.template, options).render
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def simple_type
|
|
79
|
+
:none
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require 'caring_form/field/base'
|
|
2
|
+
|
|
3
|
+
module CaringForm
|
|
4
|
+
module Field
|
|
5
|
+
class Tel < Base
|
|
6
|
+
register :tel
|
|
7
|
+
|
|
8
|
+
def simple_type
|
|
9
|
+
:string
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def apply_to_model(klass)
|
|
13
|
+
super
|
|
14
|
+
klass.send(:validates_format_of, name, :allow_blank => true,
|
|
15
|
+
:with => regexp, :message => message, :multiline => true)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def input_properties(form, options = {})
|
|
19
|
+
super.tap do |req|
|
|
20
|
+
req[:input_html][:pattern] ||= regexp.source
|
|
21
|
+
req[:input_html][:title] ||= message
|
|
22
|
+
req[:input_html][:type] ||= 'tel'
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
def regexp
|
|
29
|
+
/^\s*1?[-. \(]*([2-9][0-8][0-9])[-. \)]*([2-9][0-9]{2})[-. ]*([0-9]{4}\s*)(\s+[ext]+\s*(\d+|))?$/
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def message
|
|
33
|
+
"Enter your phone number with area code like this: XXX-XXX-XXXX"
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require 'caring_form/field/base'
|
|
2
|
+
|
|
3
|
+
module CaringForm
|
|
4
|
+
module Field
|
|
5
|
+
class UsZipCode < Base
|
|
6
|
+
register :us_zip_code
|
|
7
|
+
|
|
8
|
+
def simple_type
|
|
9
|
+
:string
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def apply_to_model(klass)
|
|
13
|
+
super
|
|
14
|
+
klass.send(:validates_format_of, name, :allow_blank => true,
|
|
15
|
+
:with => regexp, :message => message)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def input_properties(form, options = {})
|
|
19
|
+
super.tap do |req|
|
|
20
|
+
req[:input_html][:pattern] ||= regexp.source
|
|
21
|
+
req[:input_html][:title] ||= message
|
|
22
|
+
req[:input_html][:maxlength] ||= 10
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
def regexp
|
|
29
|
+
/[0-9]{5}|[0-9]{5}-[0-9]{4}/
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def message
|
|
33
|
+
"Enter a valid U.S. zip code"
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|