class SimpleForm::Inputs::AutocompleteInput

Public Instance Methods

input(wrapper_options = nil) click to toggle source
# File lib/simple_form/inputs/autocomplete_input.rb, line 6
def input(wrapper_options = nil)
  merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)

  @builder.text_field(attribute_name, merged_input_options) <<
      @builder.hidden_field(attribute_name, hidden_html_options)
end

Private Instance Methods

association() click to toggle source
# File lib/simple_form/inputs/autocomplete_input.rb, line 61
def association
  @association ||= begin
    association_name = attribute_name.to_s
    association_name.gsub!(/_id\z/, '')
    @builder.object.send(association_name.to_sym)
  end
end
hidden_html_options() click to toggle source
# File lib/simple_form/inputs/autocomplete_input.rb, line 24
def hidden_html_options
  {
      value: options.key?(:value) ? options[:value] : hidden_tag_value
  }
end
hidden_tag_value() click to toggle source
# File lib/simple_form/inputs/autocomplete_input.rb, line 49
def hidden_tag_value
  association.id if association
end
input_html_options() click to toggle source
Calls superclass method
# File lib/simple_form/inputs/autocomplete_input.rb, line 15
def input_html_options
  super.deep_merge(
      name:  '',
      id:    options.key?(:input_html) && options[:input_html].key?(:id) ? options[:input_html][:id] : input_tag_id,
      value: options.key?(:value) ? options[:value] : input_tag_value,
      data:  { source: options[:source] }
  )
end
input_tag_id() click to toggle source
# File lib/simple_form/inputs/autocomplete_input.rb, line 30
def input_tag_id
  "#{sanitized_object_name}_#{sanitized_attribute_name}_autocomplete"
end
input_tag_value() click to toggle source
# File lib/simple_form/inputs/autocomplete_input.rb, line 34
def input_tag_value
  return unless association

  if association.respond_to?(:label)
    association.label
  elsif association.respond_to?(:title)
    association.title
  elsif association.respond_to?(:name)
    association.name
  else
    warn "#{association.class} must respond to label, title, or name"
    nil
  end
end
sanitized_attribute_name() click to toggle source
# File lib/simple_form/inputs/autocomplete_input.rb, line 57
def sanitized_attribute_name
  @sanitized_method_name ||= attribute_name.to_s.sub(/\?$/, '')
end
sanitized_object_name() click to toggle source
# File lib/simple_form/inputs/autocomplete_input.rb, line 53
def sanitized_object_name
  @sanitized_object_name ||= object_name.to_s.gsub(/\]\[|[^-a-zA-Z0-9:.]/, '_').sub(/_$/, '')
end