cielo_assets 0.0.4 → 0.0.5

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.
data/README.md CHANGED
@@ -79,3 +79,44 @@ You can provide any arbitrary css class since you define it at your own applicat
79
79
  <%= f.cielo_controls :field %>
80
80
  <%= f.submit %>
81
81
  <% end %>
82
+
83
+ ## Validation and FieldWithErrors workaround
84
+
85
+ When rails fields fails to validate, the corresponding field is surrounded by a div with field_with_errors
86
+ class. This breaks CieloAssets behavior, because it expects input and labels are adjacent, to highlight
87
+ the checked control:
88
+
89
+ input {
90
+ display: none;
91
+ &:checked + label {
92
+ border-color: #777;
93
+ }
94
+ }
95
+
96
+ To avoid this side effect, add
97
+ [this workaround](http://stackoverflow.com/questions/5267998/rails-3-field-with-errors-wrapper-changes-the-page-appearance-how-to-avoid-t)
98
+ on your project's ``` config/application.rb ```:
99
+
100
+ config.action_view.field_error_proc = Proc.new { |html_tag, instance|
101
+ if instance.object.respond_to? "disable_field_with_errors_for_#{instance.method_name}"
102
+ html_tag.html_safe
103
+ else
104
+ "<div class=\"field_with_errors\">#{html_tag}</div>".html_safe
105
+ end
106
+ }
107
+
108
+ and declare the fields (via attr_reader or an empty method, for example)
109
+ that should not be surrounded by ``` field_with_errors ``` div when validation fails:
110
+
111
+ # supposes attribute is named cielo_flag
112
+ attr_accessible :cielo_flag
113
+
114
+ attr_reader :disable_field_with_errors_for_cielo_flag
115
+
116
+ or
117
+
118
+ # supposes attribute is named flag
119
+ attr_accessible :flag
120
+
121
+ def disable_field_with_errors_for_flag
122
+ end
@@ -22,8 +22,8 @@
22
22
  &.selectable {
23
23
  width: 60px;
24
24
  height: 60px;
25
+ cursor: pointer;
25
26
  border: 5px solid #EEE;
26
- cursor: hand;
27
27
  &:hover {
28
28
  border-color: #AAA;
29
29
  }
@@ -4,11 +4,18 @@ module CieloAssets
4
4
  id = options.delete(:id) || :cielo_controls
5
5
  style = options.delete(:style) || :horizontal
6
6
 
7
+ # object is deleted by radio_button helper,
8
+ # so it must be re-added to options every flag
9
+ object = options[:object]
10
+
7
11
  content_tag :div, id: id, class: style do
8
- [:amex,:diners,:elo,:mastercard,:mastercard_securecode,:verified_by_visa,:visa].collect { |flag|
12
+ %w(amex diners elo mastercard mastercard_securecode verified_by_visa visa).collect { |flag|
13
+ options.merge! object: object
14
+ radio = radio_button object_name, method, flag, options
15
+ radio_id = radio.to_s.scan(/id=\"([^"]*)/).flatten.first
16
+ label_options = options.merge class: "#{flag} selectable", for: radio_id
9
17
  [
10
- radio_button(object_name, method, flag, options),
11
- label("#{object_name}_#{method}", flag, options.merge(class: "#{flag} selectable"))
18
+ radio, label(radio_id, flag, label_options)
12
19
  ].join.html_safe
13
20
  }.join.html_safe
14
21
  end
@@ -12,6 +12,7 @@ module CieloAssets
12
12
  # Monkey patches FormBuilder
13
13
  class ActionView::Helpers::FormBuilder
14
14
  def cielo_controls method, options={}
15
+ options.merge! object: @object
15
16
  @template.cielo_controls @object_name, method, options
16
17
  end
17
18
  end
@@ -1,3 +1,3 @@
1
1
  module CieloAssets
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cielo_assets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-12 00:00:00.000000000 Z
12
+ date: 2013-02-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -169,7 +169,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
169
169
  version: '0'
170
170
  segments:
171
171
  - 0
172
- hash: -1772313288410862178
172
+ hash: -665081776306586388
173
173
  required_rubygems_version: !ruby/object:Gem::Requirement
174
174
  none: false
175
175
  requirements:
@@ -178,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
178
  version: '0'
179
179
  segments:
180
180
  - 0
181
- hash: -1772313288410862178
181
+ hash: -665081776306586388
182
182
  requirements: []
183
183
  rubyforge_project:
184
184
  rubygems_version: 1.8.23