Created
October 21, 2010 16:55
-
-
Save smathy/638856 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
## subclass for chained labelling methods | |
class LabellingFormBuilder < ActionView::Helpers::FormBuilder | |
include ActionView::Helpers::TagHelper | |
def text_field_with_labelling( method, options={}) | |
label(method) + text_field_without_labelling( method, options) | |
end | |
alias_method_chain :text_field, :labelling | |
def date_select_with_labelling( method, options={}, html_options={}) | |
label(method) + date_select_without_labelling( method, options, html_options) | |
end | |
alias_method_chain :date_select, :labelling | |
def collection_select_with_labelling( method, collection, value_method, text_method, options = {}, html_options = {}) | |
label(method) + collection_select_without_labelling( method, collection, value_method, text_method, options, html_options) | |
end | |
alias_method_chain :collection_select, :labelling | |
end | |
## adding new "auto_complete" methods to the root FormBuilder | |
class ActionView::Helpers::FormBuilder | |
include ActionView::Helpers | |
def text_field_with_auto_complete( method, options={}) | |
tag = InstanceTag.new(object_name, method, self, options.delete(:object)) | |
tag_id = tag.send(:tag_id) | |
ac_tag_id = "#{tag_id}_auto_complete" | |
text_field( method, options ) + | |
content_tag( :div, '', :class => 'auto_complete', :id => ac_tag_id) + | |
javascript_tag( %{new Ajax.Autocompleter('#{tag_id}', '#{ac_tag_id}', '/cities', {method:'get',paramName:'city[name]',afterUpdateElement:getSelectionId})}) | |
end | |
def answer_field( question, options={}) | |
method = question.answer_id.to_s | |
i = method.split('_').last.to_i | |
output = '' | |
question.choices.each do |choice| | |
output << content_tag( :div, | |
radio_button( method, choice.id ) + label( "#{method}_#{choice.id}", h(choice.content) ), | |
:class => "subelement" ) + "\n" | |
end | |
return output | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment