Created
March 3, 2010 15:57
-
-
Save siannopollo/320701 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ReadonlyFormBuilder < ActionView::Helpers::FormBuilder | |
def calendar_date_select(method, options = {}) | |
text_field method, options | |
end | |
def check_box(method, options = {}, checked_value = "1", unchecked_value = "0") | |
merge_class_options 'readonly furtive', options | |
options.update :readonly => true | |
super | |
end | |
def radio_button(method, tag_value, options = {}) | |
merge_class_options 'readonly furtive', options | |
options.update :readonly => true | |
super | |
end | |
def select(method, choices, options = {}, html_options = {}) | |
text_field method, html_options | |
end | |
def state_select(method, options = {}, html_options = {}) | |
text_field method, html_options | |
end | |
def text_area(method, options = {}) | |
text_field method, options | |
end | |
def text_field(method, options = {}) | |
merge_class_options 'readonly furtive', options | |
value = object.send(method) | |
options.update :readonly => true, :value => value | |
super | |
end | |
protected | |
def merge_class_options(classes, options) | |
options[:class] ||= '' | |
old_classes = options[:class].split(' ') | |
new_classes = classes.split(' ') | |
old_classes.concat new_classes | |
options[:class] = old_classes * ' ' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment