public
Description: A Rails Form Builder with semantically rich and accessible markup. It's not production ready yet, but I want it to be!
Clone URL: git://github.com/justinfrench/formtastic.git
Search Repo:
added a new boolean_select input, for boolean fields that work better with 
a 'yes/no' select box rather than a checkbox -- might even make this the 
default for booleans?
justinfrench (author)
Sun Jul 06 05:13:23 -0700 2008
commit  2007904bedfeb1897f44c3f2c222d8d822654977
tree    ced6dd66684b8870240a306e9de1557f40d98439
parent  a32935f238542f7061044539370edb0425927f42
...
64
65
66
 
67
68
69
...
64
65
66
67
68
69
70
0
@@ -64,6 +64,7 @@ h2. The Available Inputs
0
 * :datetime (a date and time select) - default for :datetime and :timestamp column types
0
 * :time (a time select) - default for :time column types
0
 * :boolean (a checkbox) - default for :boolean column types
0
+* :boolean_select (a yes/no select box)
0
 * :string (a text field) - default for :string column types
0
 * :numeric (a text field, like string) - default for :integer, :float and :decimal column types
0
 
...
69
70
71
 
72
73
74
...
357
358
359
360
361
362
 
 
363
364
365
366
367
368
369
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
370
371
372
...
69
70
71
72
73
74
75
...
358
359
360
 
 
 
361
362
363
364
365
366
367
368
 
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
0
@@ -69,6 +69,7 @@ module JustinFrench #:nodoc:
0
       # * :datetime (a date and time select) - default for :datetime and :timestamp column types
0
       # * :time (a time select) - default for :time column types
0
       # * :boolean (a checkbox) - default for :boolean column types
0
+ # * :boolean_select (a yes/no select box)
0
       # * :string (a text field) - default for :string column types
0
       # * :numeric (a text field, like string) - default for :integer, :float and :decimal column types
0
       #
0
@@ -357,16 +358,29 @@ module JustinFrench #:nodoc:
0
       end
0
             
0
        
0
- # Outputs a label containing a checkbox and the label text.
0
- #
0
- # TODO - what about a yes/no boolean?
0
+ # Outputs a label containing a checkbox and the label text. The label defaults to the column
0
+ # name (method name) and can be altered with the :label option.
0
       def boolean_input(method, options)
0
         input_label(method, options,
0
           @template.check_box(@object_name, method) +
0
           label_text(method, options)
0
         )
0
       end
0
-
0
+
0
+ # Outputs a label and select box containing two options for "true" and "false". The visible
0
+ # text defaults to "Yes" and "No" respectively, but can be altered with the :true and :false
0
+ # options. The label text to the column name (method name), but can be altered with the
0
+ # :label option. Example:
0
+ #
0
+ # f.input :awesome, :as => :boolean_select, :true => "Yeah!", :false => "Nah!", :label => "Awesome?"
0
+ def boolean_select_input(method, options)
0
+ options[:true] ||= "Yes"
0
+ options[:false] ||= "No"
0
+
0
+ choices = [ [options[:true],1], [options[:false],0] ]
0
+ input_label(method, options) + @template.select(@object_name, method, choices)
0
+ end
0
+
0
       def inline_errors(method, options) #:nodoc:
0
         errors = @template.instance_eval("@#{@object_name}").errors.on(method).to_a
0
         errors.empty? ? '' : @template.content_tag(:p, errors.to_sentence, :class => 'inline-errors')

Comments

    No one has commented yet.