Class: Penknife::EnhancedFormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- Penknife::EnhancedFormBuilder
- Includes:
- ActionView::Helpers::FormTagHelper, ActionView::Helpers::TagHelper
- Defined in:
- lib/penknife/enhanced_form_builder.rb
Instance Method Summary collapse
- #check_box(method, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object
- #radio_button(method, tag_value, options = {}) ⇒ Object
- #select(method, choices, options = {}, html_options = {}) ⇒ Object
- #submit(value = "Save changes", options = {}) ⇒ Object
- #submit_button(value = "Save changes", options = {}) ⇒ Object
Instance Method Details
#check_box(method, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object
15 16 17 18 19 |
# File 'lib/penknife/enhanced_form_builder.rb', line 15 def check_box(method, = {}, checked_value = "1", unchecked_value = "0") within_form_row(method, 'check_box', ) do @template.check_box(@object_name, method, (), checked_value, unchecked_value) end end |
#radio_button(method, tag_value, options = {}) ⇒ Object
27 28 29 |
# File 'lib/penknife/enhanced_form_builder.rb', line 27 def (method, tag_value, = {}) @template.(@object_name, method, tag_value, ()) end |
#select(method, choices, options = {}, html_options = {}) ⇒ Object
21 22 23 24 25 |
# File 'lib/penknife/enhanced_form_builder.rb', line 21 def select(method, choices, = {}, = {}) within_form_row(method, 'check_box', ) do @template.select(@object_name, method, choices, (), @default_options.merge()) end end |
#submit(value = "Save changes", options = {}) ⇒ Object
31 32 33 34 35 |
# File 'lib/penknife/enhanced_form_builder.rb', line 31 def submit(value = "Save changes", = {}) within_form_row(' ', nil, .merge(:title => '')) do (value, .reverse_merge(:id => "#{object_name}_submit")) end end |
#submit_button(value = "Save changes", options = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/penknife/enhanced_form_builder.rb', line 37 def (value = "Save changes", = {}) .stringify_keys! if disable_with = .delete("disable_with") disable_with = "this.value='#{disable_with}'" disable_with << ";#{.delete('onclick')}" if ['onclick'] ["onclick"] = [ "this.setAttribute('originalValue', this.value)", "this.disabled=true", disable_with, "result = (this.form.onsubmit ? (this.form.onsubmit() ? this.form.submit() : false) : this.form.submit())", "if (result == false) { this.value = this.getAttribute('originalValue'); this.disabled = false }", "return result;", ].join(";") end if confirm = .delete("confirm") ["onclick"] ||= '' ["onclick"] += "return #{confirm_javascript_function(confirm)};" end tag(:button, { "type" => "submit", "name" => "commit" }.update(.stringify_keys), true) + value + "</button>" end |