Class: Cms::FormField

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
DefaultAccessible
Defined in:
app/models/cms/form_field.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DefaultAccessible

non_permitted_params, permitted_params

Instance Attribute Details

#delete_pathObject

Returns the value of attribute delete_path.



8
9
10
# File 'app/models/cms/form_field.rb', line 8

def delete_path
  @delete_path
end

#edit_pathObject

Returns the value of attribute edit_path.



8
9
10
# File 'app/models/cms/form_field.rb', line 8

def edit_path
  @edit_path
end

Class Method Details

.permitted_paramsObject

Don’t allow name to be set via UI.



67
68
69
# File 'app/models/cms/form_field.rb', line 67

def self.permitted_params
  super - [:name]
end

Instance Method Details

#asSymbol

Return the form widget that should be used to render this field.

Returns:

  • (Symbol)

    A SimpleForm input mapping (i.e. :string, :text)



28
29
30
31
32
33
34
35
36
37
# File 'app/models/cms/form_field.rb', line 28

def as
  case field_type
    when "text_field"
      :string
    when "text_area"
      :text
    else
      field_type.to_sym
  end
end

#as_json(options = {}) ⇒ Object



20
21
22
# File 'app/models/cms/form_field.rb', line 20

def as_json(options={})
  super(:methods => [:edit_path, :delete_path])
end

#options(config = {}) ⇒ Hash

Return options to be passed to a SimpleForm input.

Parameters:

  • config (Hash) (defaults to: {})

Options Hash (config):

  • :disabled (Boolean)

    If the field should be disabled.

  • :entry (FormEntry)

Returns:

  • (Hash)


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/models/cms/form_field.rb', line 44

def options(config={})
  opts = {label: label}
  if field_type != "text_field"
    opts[:as] = self.as
  end
  if config[:disabled]
    opts[:disabled] = true
    opts[:readonly] = 'readonly'
  end
  opts[:required] = !!required
  opts[:hint] = instructions if instructions
  unless choices.blank?
    opts[:collection] = parse_choices
    opts[:prompt] = !self.required?
  end
  unless config[:entry] && config[:entry].send(name)
    opts[:input_html] =  {value: default_value}
  end
  opts
end