Module: EgovUtils::Helpers::FormHelper
- Defined in:
- lib/egov_utils/helpers/form_helper.rb
Instance Method Summary collapse
-
#fileuid_field(object_name, method, options = {}) ⇒ Object
Returns an input tag of the “fileuid” type tailored for accessing a specified attribute (identified by
method
) on an object assigned to the template (identified byobject
). - #select2(object_name, method, choices = nil, options = {}, html_options = {}, &block) ⇒ Object
Instance Method Details
#fileuid_field(object_name, method, options = {}) ⇒ Object
Returns an input tag of the “fileuid” type tailored for accessing a specified attribute (identified by method
) on an object assigned to the template (identified by object
). Additional options on the input tag can be passed as a hash with options
.
8 9 10 |
# File 'lib/egov_utils/helpers/form_helper.rb', line 8 def fileuid_field(object_name, method, = {}) Tags::FileuidField.new(object_name, method, self, ).render end |
#select2(object_name, method, choices = nil, options = {}, html_options = {}, &block) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/egov_utils/helpers/form_helper.rb', line 12 def select2(object_name, method, choices = nil, = {}, = {}, &block) select2_data_hash = {provide: 'select2'} if .delete(:include_blank) || [:prompt] select2_data_hash['allow-clear'] = true select2_data_hash['placeholder'] = .delete(:prompt) || '' end if choices.is_a?(Hash) select2_data_hash[:ajax] = choices choices = [] if [:object] && [:object].public_send(method) value_text = .delete(:value_text) || ->(object){ [:object].public_send(method.to_s.gsub(/_id$/, '')).to_s } choices << [value_text.respond_to?(:call) ? value_text.call([:object]) : value_text, [:object].public_send(method)] end end select(object_name, method, choices, , .deep_merge(data: select2_data_hash)) end |