Module: FriendsLabeledFormHelper
- Defined in:
- app/helpers/friends_labeled_form_helper.rb
Class Method Summary collapse
Instance Method Summary collapse
- #label_tag_for(object_name, method, options = {}) ⇒ Object
- #labeled_check_box(object_name, method, options = {}, checked_value = 1, unchecked_value = 0) ⇒ Object
- #labeled_radio_button(object_name, method, value, options = {}) ⇒ Object
- #labeled_text_field(object_name, method, options = {}) ⇒ Object
Class Method Details
.included(arg) ⇒ Object
4 5 6 |
# File 'app/helpers/friends_labeled_form_helper.rb', line 4 def self.included(arg) ActionView::Helpers::FormBuilder.send(:include, FriendsLabeledFormBuilder) end |
Instance Method Details
#label_tag_for(object_name, method, options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/helpers/friends_labeled_form_helper.rb', line 8 def label_tag_for(object_name, method, = {}) label_name = ([:label].blank? ? method.to_label : [:label]) label_name += [:append] unless [:append].nil? label_text = "<span class='label-text'>#{label_name}</span>" if [:errors] label_text << tooltip_box([:errors].join("<br />")) elsif ![:hide_tooltip] == true # check if tooltip is given by options if [:tooltip].present? label_text << tooltip_box([:tooltip]) elsif #look for tooltips for field in locale i18n_str = "form_tooltips.#{object_name}.#{method}" tt = begin I18n.t(i18n_str) rescue i18n_str end # we dont want to see the empty boxes on production if tt == i18n_str && !Rails.env.production? label_text << tooltip_box(tt, fallback: true) else label_text << tooltip_box(tt) end end end = {} .merge!(:class => [:class]) unless [:class].blank? .merge!(:for => [:for]) unless [:for].blank? .merge!(:id => [:id]) unless [:id].blank? return label(object_name, method, label_text.html_safe, ).html_safe end |
#labeled_check_box(object_name, method, options = {}, checked_value = 1, unchecked_value = 0) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/helpers/friends_labeled_form_helper.rb', line 71 def labeled_check_box(object_name, method, ={}, checked_value=1, unchecked_value=0) method = method.to_s.to_sym box_id = object_name.to_s+"_"+method.to_s html = "<div class='cf labeled-check-box'>" html += "<div class='checkbox-container'>#{check_box(object_name, method, .merge!(:id => box_id), checked_value, unchecked_value)}</div>" html += "<div class='checkbox-label-container'>#{label_tag_for(object_name, method, :label => [:label], :tooltip => [:tooltip], :class => "checkbox-label", :for => box_id, :errors => [:errors])}</div>" html += "</div>" return html.html_safe end |
#labeled_radio_button(object_name, method, value, options = {}) ⇒ Object
85 86 87 88 89 90 91 92 93 94 |
# File 'app/helpers/friends_labeled_form_helper.rb', line 85 def (object_name, method, value, = {}) [:id] ||= "radio-#{method.to_s}-#{value.inspect}" [:label] ||= method.to_label html = "<div class='cf labeled-radio-button'>" html << (object_name, method, value, .except(:label, :errors)) html << " " html << label_tag_for(object_name, method, {:label => [:label], :for => [:id]}) html << "</div>" return raw(html) end |
#labeled_text_field(object_name, method, options = {}) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/helpers/friends_labeled_form_helper.rb', line 48 def labeled_text_field(object_name, method, ={}) if [:id] = .merge(:id => "label-#{[:id]}") else = end if [:label_as_placeholder].present? html = "" [:placeholder] = [:label_as_placeholder] else html = label_tag_for(object_name, method, ) end if [:password] && .delete(:password) html += password_field(object_name, method, ) else html += text_field(object_name, method, ) end return html.html_safe end |