Class: BootstrapForms::FormBuilder
- Inherits:
-
Padrino::Helpers::FormBuilder::AbstractFormBuilder
- Object
- Padrino::Helpers::FormBuilder::AbstractFormBuilder
- BootstrapForms::FormBuilder
- Includes:
- Helpers::Wrappers
- Defined in:
- lib/bootstrap_forms/form_builder.rb
Instance Method Summary collapse
- #actions(&block) ⇒ Object
- #button(*args) ⇒ Object
- #cancel(*args) ⇒ Object
- #check_box(name, *args) ⇒ Object
- #collection_check_boxes(attribute, records, record_id, record_name, *args) ⇒ Object
- #collection_radio_buttons(attribute, records, record_id, record_name, *args) ⇒ Object
-
#initialize(*args) ⇒ FormBuilder
constructor
A new instance of FormBuilder.
- #radio_buttons(name, values = {}, opts = {}) ⇒ Object
- #submit(*args) ⇒ Object
- #uneditable_input(name, *args) ⇒ Object
Constructor Details
#initialize(*args) ⇒ FormBuilder
Returns a new instance of FormBuilder.
7 8 9 10 |
# File 'lib/bootstrap_forms/form_builder.rb', line 7 def initialize(*args) @field_options = {} super(*args) end |
Instance Method Details
#actions(&block) ⇒ Object
129 130 131 132 |
# File 'lib/bootstrap_forms/form_builder.rb', line 129 def actions(&block) content = block_given? ? capture_html(&block) : [submit, cancel].join(' ') content_tag(:div, content, :class => 'form-actions').html_safe end |
#button(*args) ⇒ Object
117 118 119 |
# File 'lib/bootstrap_forms/form_builder.rb', line 117 def (*args) template.(*args) end |
#cancel(*args) ⇒ Object
125 126 127 |
# File 'lib/bootstrap_forms/form_builder.rb', line 125 def cancel(*args) template.bootstrap_cancel_tag(*args) end |
#check_box(name, *args) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/bootstrap_forms/form_builder.rb', line 25 def check_box(name, *args) @name = name @field_options = args. control_group_div do input_div(false) do if @field_options[:label] == false || @field_options[:label] == '' super(name, (@field_options)) << else html = super(name, (@field_options)) << (@field_options[:label].blank? ? @name.to_s.humanize : @field_options[:label]) html << = { :caption => html, :class => 'checkbox' } [:for] = @field_options[:id] if @field_options.include?(:id) label(@name, ) end end end.html_safe end |
#collection_check_boxes(attribute, records, record_id, record_name, *args) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/bootstrap_forms/form_builder.rb', line 64 def collection_check_boxes(attribute, records, record_id, record_name, *args) @name = attribute @field_options = args. boxes = records.map do |record| value = record.send(record_id) element_id = "#{object_model_name}_#{attribute}_#{value}" = (@field_options).merge(:value => value, :id => element_id) [:checked] = "checked" if [object.send(attribute)].flatten.include?(value) checkbox = check_box_tag("#{object_model_name}[#{attribute}][]", ) checkbox << record.send(record_name) content_tag(:label, checkbox, :class => ['checkbox', ('inline' if @field_options[:inline])].compact.join(' ')) end.join('').html_safe control_group_div do # Prevent "for" attribute for a non existant id @field_options[:id] = nil label_field << input_div { boxes } end.html_safe end |
#collection_radio_buttons(attribute, records, record_id, record_name, *args) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/bootstrap_forms/form_builder.rb', line 87 def (attribute, records, record_id, record_name, *args) @name = attribute @field_options = args. = records.map do |record| value = record.send(record_id) element_id = "#{object_model_name}_#{attribute}_#{value}" = (@field_options).merge(:value => value, :id => element_id) radio = (attribute, ) radio << record.send(record_name) content_tag(:label, radio, :class => ['radio', ('inline' if @field_options[:inline])].compact.join(' ')) end.join('').html_safe control_group_div do # Prevent "for" attribute for a non existant id @field_options[:id] = nil label_field << input_div { } end.html_safe end |
#radio_buttons(name, values = {}, opts = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/bootstrap_forms/form_builder.rb', line 44 def (name, values = {}, opts = {}) @name = name @field_options = opts = values.map do |text, value| # Padrino does not stringify false values html = (name, (@field_options).merge(:value => "#{value}")) html << text = { :caption => html, :class => 'radio', :for => nil } label("#{name}_#{value}", ) end.join('').html_safe control_group_div do # Prevent "for" attribute for a non existant id @field_options[:id] = nil label_field << input_div { } end.html_safe end |
#submit(*args) ⇒ Object
121 122 123 |
# File 'lib/bootstrap_forms/form_builder.rb', line 121 def submit(*args) template.bootstrap_submit_tag(*args) end |
#uneditable_input(name, *args) ⇒ Object
107 108 109 110 111 112 113 114 115 |
# File 'lib/bootstrap_forms/form_builder.rb', line 107 def uneditable_input(name, *args) @name = name @field_options = args. @field_options[:id] ||= field_id(@name) @field_options[:label] ||= "#{field_human_name(@name)}: " # conform to Padrino's default @field_options[:value] ||= object.send(@name.to_sym) template.uneditable_input_tag(@name, @field_options) end |