Hi, I just noticed that button_to generates a div inside the form element. Why? Jeroen
On 17-nov-2005, at 14:48, Jeroen Houben 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.
Julian ''Julik'' Tarkhanov wrote:> > On 17-nov-2005, at 14:48, Jeroen Houben 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.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
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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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}</span>" 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 On 12/21/06, Aryk Grosz <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > 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 > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ugh... That code should read: ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| "<span class=\"error\">#{html_tag}</span>" end RSL On 12/22/06, Russell Norris <sconds-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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}< /span>" > 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 > > > On 12/21/06, Aryk Grosz <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org > wrote: > > > > > > 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 > > > > -- > > Posted via http://www.ruby-forum.com/. > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Excellent. I just had that wreck a layout yesterday. Including this code should be easier and cleaner than hacking up the CSS. Russell Norris wrote:> Ugh... That code should read: > > ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| > "<span class=\"error\">#{html_tag}</span>" > end > > RSL > > On 12/22/06, *Russell Norris* <sconds-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > <mailto:sconds-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> wrote: > > 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}< > /span>" > 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 > > > On 12/21/06, *Aryk Grosz* < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org > <mailto:rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > > 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 > > -- > Posted via http://www.ruby-forum.com/. > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---