Class: BsReadonlyInput

Inherits:
Formtastic::Inputs::StringInput
  • Object
show all
Includes:
ActionView::Context, ActionView::Helpers::JavaScriptHelper, ActionView::Helpers::TagHelper, FontAwesome::Rails::IconHelper, FormtasticBootstrap::Inputs::Base, FormtasticBootstrap::Inputs::Base::Collections
Defined in:
app/input/bs_readonly_input.rb

Instance Method Summary collapse

Instance Method Details

#to_htmlObject

Nel caso di collection si può definire con :show_hidden => [true] per stampare il campo hidden o meno con il vero valore :display_field come options quale campo usare per stampare :value_renderer => Proc da aggiungere, a cui passiamo

 campo, valore , se passato nulla viene
renderizzato standard un p contenente il valore


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/input/bs_readonly_input.rb', line 18

def to_html

  field_name = method
  show_value = object.send(method)
  if show_value.is_a?(ActiveRecord::Base) and !options[:display_field].blank?
    #vuol dire che siamo in una collection
    show_value = show_value.send(options[:display_field])
    field_name = input_name
  end

  if !options[:value_renderer].is_a?(Proc)
    options[:value_renderer]=Proc.new { |field, value|
      buff = ActiveSupport::SafeBuffer.new
      buff<<(:p, value, class: 'form-control-static', id: "#{field.form_control_input_html_options[:id]}_container")
      buff
    }
  end


  bootstrap_wrapping do
    (:div, class: 'input-group date') do

      buff = ActiveSupport::SafeBuffer.new

      buff<< options[:value_renderer].call(self, show_value)

      buff<< builder.hidden_field(field_name, form_control_input_html_options)

      buff

    end
  end
end