Button_to generates DIV

Hi,

I just noticed that button_to generates a div inside the form element.
Why?

Jeroen

On 17-nov-2005, at 14:48, Jeroen H. wrote:

Hi,

I just noticed that button_to generates a div inside the form
element. Why?

Because it’s a requirement, per XHTML 1.1, to have an enclosing block
element as an immediate child of the FORM element.

Ugh… That code should read:

ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
“<span class=“error”>#{html_tag}”
end

RSL

hey guys, to fix this, i just hacked the button_to and url_for helpers
and included it in my application.rb:

module ActionView
module Helpers
module UrlHelper
def button_to(name, options = {}, html_options = nil)

    html_options = (html_options || {}).stringify_keys
    convert_boolean_attributes!(html_options, %w( disabled ))

    if confirm = html_options.delete("confirm")
      html_options["onclick"] = "return 

#{confirm_javascript_function(confirm)};"
end
options = {:only_path=>false}.update(options)
url = options.is_a?(String) ? options : url_for(options)
name ||= url

    html_options.symbolize_keys!
    tag(:input, html_options.merge({
      :type => "button", :value => name,
      :onclick => (html_options[:onclick] ? 

"#{html_options[:onclick]}; " : “”) +
“window.location.href=’#{url_for(options)}’;”
}))

  end


  def url_for(options = {}, *parameters_for_method_reference)
    if options.kind_of? Hash
      options = { :only_path => true 

}.update(options.symbolize_keys)
escape = options.key?(:escape) ? options.delete(:escape) :
true
else
escape = true
end
url = @controller.send(:url_for, options,
*parameters_for_method_reference)
escape ? html_escape(url).gsub(/&/,"&") : url # replaces
the ‘&’ with its original &
end

end

end
end

This is a pet peeve of mine in Rails - there are a few places where
these div’s pop up inappropriately IMHO. Any idea why?

On Dec 21 2006, 8:37 pm, Aryk G. [email protected]

You might be interested in this snippet of code I saw somewhere and use
in
all my Rails apps.

ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
“<span class=“error”>#{html_tag}”
end

That fieldWithError div [a block element] around bad form fields can
really
wreck a layout sometimes. An aptly named span works just as well.

RSL

Excellent. I just had that wreck a layout yesterday. Including this code
should be easier and cleaner than hacking up the CSS.

Julian ‘Julik’ Tarkhanov wrote:

element as an immediate child of the FORM element.
Wow. I wonder why they did that… I guess div is a good choice then.

It is a bit of a bummer that we can’t specify say a template for these
things, I mean the div is hardcoded, you can only change it if you
overwrite the button_to method altogether. Are there plans for something
like this?

Jeroen