<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -32,6 +32,7 @@ class TenplateFormBuilder &lt; ActionView::Helpers::FormBuilder
   def text_field(object_method , options={})
     label_html_attributes = label_attributes(object_method, options.delete(:label))
     tip = options.delete(:tip)
+    value = options.delete(:value) || object.respond_to?(object_method) &amp;&amp; object.send(object_method) || nil
     supported_attributes = [:class, :id, :disabled, :size, :alt, :tabindex, :accesskey, :onfocus, :onblur, :onselect, :onchange, :value]
     options.delete_if {|attribute_name, attribute_value| !supported_attributes.include?(attribute_name.to_sym)}
     @template.render :partial =&gt; &quot;form_templates/text_field&quot;,
@@ -39,7 +40,7 @@ class TenplateFormBuilder &lt; ActionView::Helpers::FormBuilder
                                  :object_method =&gt; object_method,
                                  :label_text  =&gt; label_html_attributes[:text],
                                  :label_for   =&gt; label_html_attributes[:for],
-                                 :value       =&gt; options.delete(:value),
+                                 :value       =&gt; value,
                                  :builder     =&gt; self,
                                  :scoped_by_object =&gt; true,
                                  :tip         =&gt; tip,
@@ -74,7 +75,7 @@ class TenplateFormBuilder &lt; ActionView::Helpers::FormBuilder
     selected_state       = options.delete(:selected) == true
     checked_value        = options[:checked_value].nil? ? &quot;1&quot; : options.delete(:checked_value)
     unchecked_value      = options[:unchecked_value].nil? ? &quot;0&quot; : options.delete(:unchecked_value)
-    supported_attributes = [:class, :id, :disabled, :size, :alt, :tabindex, :accesskey, :onfocus, :onblur, :onselect, :onchange]
+    supported_attributes = [:checked, :class, :id, :disabled, :size, :alt, :tabindex, :accesskey, :onfocus, :onblur, :onselect, :onchange]
     options.delete_if {|attribute_name, attribute_value| !supported_attributes.include?(attribute_name.to_sym)}
 
     @template.render :partial =&gt; 'form_templates/check_box',
@@ -91,15 +92,17 @@ class TenplateFormBuilder &lt; ActionView::Helpers::FormBuilder
   end
 
   def check_box(object_method, options = {})
-    options.delete(:label_method)
-    options.delete(:value_method)
     label_text      = options[:label] &amp;&amp; options[:label][:text] ? options[:label].delete(:text) : object_method.to_s.titleize
     label_for       = options[:label] &amp;&amp; options[:label][:for]  ? options[:label].delete(:for) : object_method
     checked_value   = options[:checked_value].nil? ? &quot;1&quot; : options.delete(:checked_value)
     unchecked_value = options[:unchecked_value].nil? ? &quot;0&quot; : options.delete(:unchecked_value)
     part_of_group   = options.delete(:part_of_group) == true
-    selected_state  = options.delete(:selected) == true
-    supported_attributes = [:class, :id, :disabled, :size, :alt, :tabindex, :accesskey, :onfocus, :onblur, :onselect, :onchange]
+    value_method    = object_method.is_a?(Hash) ? object_method.keys.first : object_method
+    if options.delete(:selected) == true || (object.respond_to?(value_method) &amp;&amp; object.send(value_method) == true)
+      selected_state = &quot;checked&quot;
+    end
+
+    supported_attributes = [:checked, :class, :id, :disabled, :size, :alt, :tabindex, :accesskey, :onfocus, :onblur, :onselect, :onchange]
     options.delete_if {|attribute_name, attribute_value| !supported_attributes.include?(attribute_name.to_sym)}
 
     @template.render :partial =&gt; 'form_templates/check_box',
@@ -136,7 +139,7 @@ class TenplateFormBuilder &lt; ActionView::Helpers::FormBuilder
     unchecked_value = 0
     field_name, label_text = checkboxable_object.is_a?(Hash) ? checkboxable_object.to_a.flatten : checkboxable_object
     if !field_name.is_a?(ActiveRecord::Base) &amp;&amp; object.respond_to?(field_name)
-      selected = Array(selected_values).include?(field_name)
+      selected = Array(selected_values).include?(field_name) || object.send(field_name) == true
       check_box(field_name, :label =&gt; {:text =&gt; label_text},
                             :selected =&gt; selected,
                             :part_of_group =&gt; part_of_group,
@@ -219,8 +222,9 @@ class TenplateFormBuilder &lt; ActionView::Helpers::FormBuilder
   def text_area(object_method, options = {})
     label_html_attributes = label_attributes(object_method, options.delete(:label))
     tip = options.delete(:tip)
-    value_method = options.delete(:value_method) || :id
-    label_method = options.delete(:label_method) || :id
+    value_method = options.delete(:value_method) || object_method
+    value =  value = options.delete(:value) || object.respond_to?(object_method) &amp;&amp; object.send(object_method)
+    label_method = options.delete(:label_method) || object_method
     supported_attributes = [:class, :id, :disabled, :size, :alt, :tabindex, :accesskey, :onfocus, :onblur, :onselect, :onchange, :value]
     options.delete_if {|attribute_name, attribute_value| !supported_attributes.include?(attribute_name.to_sym)}
 
@@ -234,6 +238,7 @@ class TenplateFormBuilder &lt; ActionView::Helpers::FormBuilder
                                   :tip                 =&gt; tip,
                                   :builder             =&gt; self,
                                   :scoped_by_object    =&gt; true,
+                                  :value               =&gt; value,
                                   :options             =&gt; options
                                  }
   end</diff>
      <filename>lib/templates/form_builder/tenplate_form_builder.rb</filename>
    </modified>
    <modified>
      <diff>@@ -5,7 +5,7 @@ end
 
 describe TenplateFormBuilder do
   before(:each) do
-    @object = mock(&quot;A Person object&quot;)
+    @object = mock(&quot;A Person object&quot;, :first_name =&gt; &quot;John&quot;, :admin =&gt; true)
     @object_name = @object
     @template = mock(&quot;View template object&quot;)
     @builder = TenplateFormBuilder.new @object, @object_name, @template, {}, nil
@@ -284,7 +284,7 @@ describe TenplateFormBuilder do
          :label_for =&gt; :first_name,
          :scoped_by_object =&gt; true,
          :tip =&gt; nil,
-         :value =&gt; nil,
+         :value =&gt; &quot;John&quot;,
          :options =&gt; {}
         }.each_pair do |key, value|
           it &quot;renders the template with '#{key}' set to '#{value}'&quot;  do
@@ -294,6 +294,14 @@ describe TenplateFormBuilder do
           end
         end
 
+        context &quot;with an invalid method_name&quot; do
+          it &quot;renders an empty textfield&quot; do
+            expected_render_arguments = hash_including(:locals =&gt; hash_including(:value =&gt; nil))
+            @template.should_receive(:render).with(expected_render_arguments).and_return(lambda {&quot;Template rendered&quot;})
+            @builder.text_field(:invalid_field_name).should_not raise_error
+          end
+        end
+
         it_should_behave_like &quot;Any labeled input type&quot;
         it_should_behave_like &quot;Any self-cleaning input type&quot;
 
@@ -333,7 +341,14 @@ describe TenplateFormBuilder do
       it_should_behave_like &quot;Any self-cleaning input type&quot;
       it_should_behave_like &quot;Any labeled input type&quot;
       it_should_behave_like &quot;Any tipable input type&quot;
-      it_should_behave_like &quot;Any scoped input accepting 'value_method' and 'label_method' attributes&quot;
+
+      it &quot;passes ':biography' as the 'value_method' to the view template&quot; do
+        check_options_full :passed_in =&gt; {}, :expected =&gt; {:value_method =&gt; :biography}
+      end
+
+      it &quot;passes ':biography' as the 'label_method' to the view template&quot; do
+        check_options_full :passed_in =&gt; {}, :expected =&gt; {:label_method =&gt; :biography}
+      end
     end
 
     context &quot;by calling 'text_area_tag'&quot; do
@@ -482,9 +497,10 @@ describe TenplateFormBuilder do
           end
         end
 
-        context &quot;setting 'selected'&quot; do
-          before(:each) {testing_option :selected, :selected_state}
-          it_should_behave_like &quot;Any boolean option&quot;
+        context &quot;setting 'selected' to true&quot; do
+          it &quot;passes a 'selected_state' of 'checked' to the view template&quot; do
+            check_options_full :passed_in =&gt; {:selected =&gt; true}, :expected =&gt; {:selected_state =&gt; &quot;checked&quot;}
+          end
         end
 
         context &quot;setting 'part_of_group'&quot; do
@@ -737,7 +753,7 @@ describe TenplateFormBuilder do
         @builder.check_box(@hash_of_roles, validations[:passed_in]).should_not raise_error
       end
 
-      {:selected =&gt; false,
+      {:selected =&gt; true,
        :part_of_group =&gt; false,
        :checked_value =&gt; 1,
        :unchecked_value =&gt; 0</diff>
      <filename>spec/templates/form_builder/tenplate_form_builder_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>9014d178ae793e5bb9dd2f4248edfbf61af4c866</id>
    </parent>
  </parents>
  <author>
    <name>Tom Kersten</name>
    <email>tkersten@obtiva.com</email>
  </author>
  <url>http://github.com/danboy/tenplate/commit/513ff83dc4a461345ed43052a0d37d02c1ed592d</url>
  <id>513ff83dc4a461345ed43052a0d37d02c1ed592d</id>
  <committed-date>2009-03-09T21:43:29-07:00</committed-date>
  <authored-date>2009-03-09T21:43:29-07:00</authored-date>
  <message>Updated form builder to correctly restore checkbox values
- User previously was forced to pass in a &quot;selected&quot; attribute
  which fit for many cases, but not the simplest ActiveRecord
  field case. This has been resolved.
- Updated associated specs...</message>
  <tree>fee1d6853e98c4ab5f7c2537ab956b3705b6fc94</tree>
  <committer>
    <name>Tom Kersten</name>
    <email>tkersten@obtiva.com</email>
  </committer>
</commit>
