Class: Formtastic::Inputs::TokenInput

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/formtastic/inputs/token_input.rb

Instance Method Summary collapse

Instance Method Details

#input_html_optionsObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/formtastic/inputs/token_input.rb', line 13

def input_html_options
  super.merge({
   :required          => nil,
   :autofocus         => nil,
   :class             => 'token-input',
   'data-model-name' => reflection.klass.model_name.singular
  }).tap do |html_options|
    if record.present?
      html_options["data-pre"] = prepopulated_value.to_json
    end
  end
end

#name_methodObject



30
31
32
# File 'lib/formtastic/inputs/token_input.rb', line 30

def name_method
  builder.collection_label_methods.find { |m| record.respond_to?(m) }
end

#name_valueObject



34
35
36
# File 'lib/formtastic/inputs/token_input.rb', line 34

def name_value
  record.send(name_method)
end

#prepopulated_valueObject



26
27
28
# File 'lib/formtastic/inputs/token_input.rb', line 26

def prepopulated_value
  [{"value" => name_value, "id" => record.id}]
end

#recordObject



38
39
40
# File 'lib/formtastic/inputs/token_input.rb', line 38

def record
  @object.send(method)
end

#to_htmlObject



6
7
8
9
10
11
# File 'lib/formtastic/inputs/token_input.rb', line 6

def to_html
  input_wrapping do
    label_html <<
      builder.hidden_field(input_name, input_html_options)
  end
end