bureaucrat 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/bureaucrat/fields.rb +9 -5
- data/lib/bureaucrat/forms.rb +2 -2
- data/lib/bureaucrat/widgets.rb +12 -12
- metadata +1 -1
data/lib/bureaucrat/fields.rb
CHANGED
@@ -353,7 +353,7 @@ module Fields
|
|
353
353
|
|
354
354
|
def clean(value)
|
355
355
|
case value
|
356
|
-
when true, 'true', '1' then true
|
356
|
+
when true, 'true', '1', 'on' then true
|
357
357
|
when false, 'false', '0' then false
|
358
358
|
else nil
|
359
359
|
end
|
@@ -393,13 +393,17 @@ module Fields
|
|
393
393
|
end
|
394
394
|
|
395
395
|
def valid_value?(value)
|
396
|
-
@choices.
|
397
|
-
if v.is_a?(Array)
|
398
|
-
|
396
|
+
@choices.each do |k, v|
|
397
|
+
if v.is_a?(Array)
|
398
|
+
# This is an optgroup, so look inside the group for options
|
399
|
+
v.each do |k2, v2|
|
400
|
+
return true if value == k2.to_s
|
401
|
+
end
|
399
402
|
else
|
400
|
-
value == k.to_s
|
403
|
+
return true if value == k.to_s
|
401
404
|
end
|
402
405
|
end
|
406
|
+
false
|
403
407
|
end
|
404
408
|
end
|
405
409
|
|
data/lib/bureaucrat/forms.rb
CHANGED
@@ -116,8 +116,8 @@ module Bureaucrat; module Forms
|
|
116
116
|
|
117
117
|
def initialize(data=nil, options={})
|
118
118
|
@is_bound = !data.nil?
|
119
|
-
@data =
|
120
|
-
|
119
|
+
@data = {}
|
120
|
+
data.each {|k, v| @data[k.to_sym] = @data[k] = v} if data
|
121
121
|
@files = options.fetch(:files, {})
|
122
122
|
@auto_id = options.fetch(:auto_id, 'id_%s')
|
123
123
|
@prefix = options[:prefix]
|
data/lib/bureaucrat/widgets.rb
CHANGED
@@ -133,7 +133,7 @@ module Widgets
|
|
133
133
|
end
|
134
134
|
|
135
135
|
def value_from_datahash(data, files, name)
|
136
|
-
|
136
|
+
data[name]
|
137
137
|
end
|
138
138
|
|
139
139
|
def self.id_for_label(id_)
|
@@ -250,17 +250,17 @@ module Widgets
|
|
250
250
|
end
|
251
251
|
|
252
252
|
class Textarea < Widget
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
253
|
+
def initialize(attrs=nil)
|
254
|
+
# The 'rows' and 'cols' attributes are required for HTML correctness.
|
255
|
+
@attrs = {:cols => '40', :rows => '10'}
|
256
|
+
@attrs.merge!(attrs) if attrs
|
257
|
+
end
|
258
258
|
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
259
|
+
def render(name, value, attrs=nil)
|
260
|
+
value ||= ''
|
261
|
+
final_attrs = build_attrs(attrs, :name => name)
|
262
|
+
mark_safe("<textarea#{flatatt(final_attrs)}>#{conditional_escape(value.to_s)}</textarea>")
|
263
|
+
end
|
264
264
|
end
|
265
265
|
|
266
266
|
# DateInput
|
@@ -275,7 +275,7 @@ module Widgets
|
|
275
275
|
|
276
276
|
def render(name, value, attrs=nil)
|
277
277
|
final_attrs = build_attrs(attrs, :type => 'checkbox', :name => name.to_s)
|
278
|
-
result =
|
278
|
+
result = @check_test.call(value) rescue false
|
279
279
|
final_attrs[:checked] = 'checked' if result
|
280
280
|
final_attrs[:value] = value.to_s unless
|
281
281
|
['', true, false, nil].include?(value)
|