Skip to content

Commit

Permalink
Fixed form helper's name attribute for question methods
Browse files Browse the repository at this point in the history
  • Loading branch information
avit authored and rick committed May 6, 2008
1 parent 123e556 commit 04f5221
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
14 changes: 9 additions & 5 deletions actionpack/lib/action_view/helpers/form_helper.rb
Expand Up @@ -614,23 +614,27 @@ def add_default_name_and_id(options)
end

def tag_name
"#{@object_name}[#{@method_name}]"
"#{@object_name}[#{sanitized_method_name}]"
end

def tag_name_with_index(index)
"#{@object_name}[#{index}][#{@method_name}]"
"#{@object_name}[#{index}][#{sanitized_method_name}]"
end

def tag_id
"#{sanitized_object_name}_#{@method_name}"
"#{sanitized_object_name}_#{sanitized_method_name}"
end

def tag_id_with_index(index)
"#{sanitized_object_name}_#{index}_#{@method_name}"
"#{sanitized_object_name}_#{index}_#{sanitized_method_name}"
end

def sanitized_object_name
@object_name.gsub(/[^-a-zA-Z0-9:.]/, "_").sub(/_$/, "")
@sanitized_object_name ||= @object_name.gsub(/[^-a-zA-Z0-9:.]/, "_").sub(/_$/, "")
end

def sanitized_method_name
@sanitized_method_name ||= @method_name.sub(/\?$/,"")
end
end

Expand Down
9 changes: 9 additions & 0 deletions actionpack/test/template/form_helper_test.rb
Expand Up @@ -6,6 +6,7 @@
alias_method :title_before_type_cast, :title unless respond_to?(:title_before_type_cast)
alias_method :body_before_type_cast, :body unless respond_to?(:body_before_type_cast)
alias_method :author_name_before_type_cast, :author_name unless respond_to?(:author_name_before_type_cast)
alias_method :secret?, :secret

def new_record=(boolean)
@new_record = boolean
Expand Down Expand Up @@ -71,10 +72,12 @@ def test_label
'<label class="title_label" for="post_title">Title</label>',
label("post", "title", nil, :class => 'title_label')
)
assert_dom_equal('<label for="post_secret">Secret?</label>', label("post", "secret?"))
end

def test_label_with_symbols
assert_dom_equal('<label for="post_title">Title</label>', label(:post, :title))
assert_dom_equal('<label for="post_secret">Secret?</label>', label(:post, :secret?))
end

def test_label_with_for_attribute_as_symbol
Expand Down Expand Up @@ -140,6 +143,8 @@ def test_text_field_doesnt_change_param_values
def test_hidden_field
assert_dom_equal '<input id="post_title" name="post[title]" type="hidden" value="Hello World" />',
hidden_field("post", "title")
assert_dom_equal '<input id="post_secret" name="post[secret]" type="hidden" value="1" />',
hidden_field("post", "secret?")
end

def test_hidden_field_with_escapes
Expand Down Expand Up @@ -172,6 +177,10 @@ def test_check_box
'<input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />',
check_box("post", "secret")
)
assert_dom_equal(
'<input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />',
check_box("post", "secret?")
)
end

def test_check_box_with_explicit_checked_and_unchecked_values
Expand Down

0 comments on commit 04f5221

Please sign in to comment.