Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fixing issue #2492. ActionView::Base.field_error_proc doesn't call for la #2493

Closed
wants to merge 1 commit into from

2 participants

@kryzhovnik

Fixing issue #2492. ActionView::Base.field_error_proc doesn't call for label.

objectify_options method should be applied to the proper options arg.

@arunagw
Collaborator

Hi @kryzhovnik Just want to followup with this issue. Is this still a issue or this can be closed??

Cheers,
Arun

@kryzhovnik kryzhovnik Fixing issue #2492 for master branch. ActionView::Base.field_error_pr…
…oc doesn't call for label.

objectify_options method should be applied to the proper options arg.

See explanation and example of the bug - https://github.com/kryzhovnik/rails_field_error_proc_bug_example
6ce0a6d
@kryzhovnik

Hi @arunagw
This bug was fixed neither in master nor in 3-2-stable. However that pull-request is irrelevant now. I've create two new pull requests.
for 3-2-stable #5614
for master #5615

@kryzhovnik kryzhovnik closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 27, 2012
  1. @kryzhovnik

    Fixing issue #2492 for master branch. ActionView::Base.field_error_pr…

    kryzhovnik authored
    …oc doesn't call for label.
    
    objectify_options method should be applied to the proper options arg.
    
    See explanation and example of the bug - https://github.com/kryzhovnik/rails_field_error_proc_bug_example
This page is out of date. Refresh to see the latest.
View
11 actionpack/lib/action_view/helpers/form_helper.rb
@@ -1117,10 +1117,17 @@ def fields_for(record_name, record_object = nil, fields_options = {}, &block)
@template.fields_for(record_name, record_object, fields_options, &block)
end
- def label(method, text = nil, options = {}, &block)
- @template.label(@object_name, method, text, objectify_options(options), &block)
+ def label(method, content_or_options = nil, options = {}, &block)
+ if content_or_options.is_a?(Hash)
+ content_or_options = objectify_options(content_or_options)
+ else
+ options = objectify_options(options)
+ end
+
+ @template.label(@object_name, method, content_or_options, options, &block)
end
+
def check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
@template.check_box(@object_name, method, objectify_options(options), checked_value, unchecked_value)
end
View
22 actionpack/test/template/form_helper_test.rb
@@ -1046,6 +1046,28 @@ def test_form_for_with_nil_index_option_override
assert_dom_equal expected, output_buffer
end
+ def test_form_for_label_error_wrapping_without_conventional_instance_variable
+ post = remove_instance_variable :@post
+ default_field_error_proc = ActionView::Base.field_error_proc
+ ActionView::Base.field_error_proc = Proc.new{ |html_tag, instance| "<div class='error'>#{html_tag}</div>".html_safe }
+
+ form_for(post) do |f|
+ concat f.label(:author_name, :class => 'label')
+ concat f.text_field(:author_name)
+ concat f.submit('Create post')
+ end
+
+ expected = whole_form('/posts/123', 'edit_post_123' , 'edit_post', 'patch') do
+ "<div class='error'><label for='post_author_name' class='label'>Author name</label></div>" +
+ "<div class='error'><input name='post[author_name]' type='text' id='post_author_name' value='' /></div>" +
+ "<input name='commit' type='submit' value='Create post' />"
+ end
+
+ assert_dom_equal expected, output_buffer
+ ensure
+ ActionView::Base.field_error_proc = default_field_error_proc
+ end
+
def test_form_for_with_namespace
form_for(@post, :namespace => 'namespace') do |f|
concat f.text_field(:title)
Something went wrong with that request. Please try again.