Skip to content

Instantly share code, notes, and snippets.

@prathamesh-sonpatki
Created January 17, 2015 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prathamesh-sonpatki/49dfe395e4a8820cbb34 to your computer and use it in GitHub Desktop.
Save prathamesh-sonpatki/49dfe395e4a8820cbb34 to your computer and use it in GitHub Desktop.
module ActionView
module Helpers
module Tags # :nodoc:
class Base # :nodoc:
def options_for_rendering(default_options)
default_options
end
end
class TextField < Base # :nodoc:
def render
tag("input", options_for_rendering(default_options_for_rendering))
end
def default_options_for_rendering
options = @options.stringify_keys
options["size"] = options["maxlength"] unless options.key?("size")
options["type"] ||= field_type
options["value"] = options.fetch("value") { value_before_type_cast(object) } unless field_type == "file"
add_default_name_and_id(options)
options
end
end
end
end
end
class ActionView::Helpers::Tags::TextField
def options_for_rendering(default_options)
default_options["aria-labelledby"] = "label_#{default_options["id"]}"
default_options["aria-required"] = true
default_options
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment