Class: CellsV1::Input::Cell
- Inherits:
-
Cell
- Object
- Cell
- CellsV1::Input::Cell
- Defined in:
- app/cells/lato_view/cells_v1/input/cell.rb
Overview
Cella Input
Constant Summary collapse
- @@types =
Lista di tipologie di input accettate
%w(text number select password email editor checkbox radio textarea file date multiple-select time)- @@widths =
Lista dei parametri accettati per l’attributo width
VIEW_INPUTWIDTH
Instance Attribute Summary collapse
-
#custom_class ⇒ Object
Classi custom da inserire nel codice dell’input * default: nil.
-
#disabled ⇒ Object
Valore che indica se disattivare o meno l’input * default: false.
-
#label ⇒ Object
Testo da inserire nella label dell’input * default: nil.
-
#multiple_files ⇒ Object
Valore che indica (nel caso di input file) se accettare piu’ file o uno singolarmente * default: false.
-
#name ⇒ Object
Nome da assegnare all’input * default: ‘input’.
-
#option_blank ⇒ Object
Valore booleano che indica (nel caso di input select) se mostrare o meno la prima opzione del select vuota * default: false.
-
#options ⇒ Object
Lista di opzioni da mostrare (nel caso di input select o radio buttons e checkbox).
-
#password_visible ⇒ Object
Valore booleano che indica (nel caso di input password) se mostrare il pulsante per vedere la password * default: true.
-
#placeholder ⇒ Object
Valore da inserire come placeholder all’input * default: nil.
-
#required ⇒ Object
Valore booleano usato per indicare se l’input e’ obbligatorio nel form in cui si trova * default: false.
-
#type ⇒ Object
Tipologia di input da inizializzare (text, number, select, password, email, multiple-select, date, checkbox, radio, textarea, file) * default: ‘text’.
-
#value ⇒ Object
Valore gia’ impostato nell’input * default: nil.
-
#width ⇒ Object
Dimensione dell’input (half, third, fourth, two-third) * default: nil (‘large’).
Class Method Summary collapse
-
.generate_options_from_activerecords(activerecords, value, name) ⇒ Object
Funzione che prende in input un activerecords, il nome dell’attributo da usare come valore e il nome dell’attributo da usare come nome e ritorna un array da usare come options per un input select o un radio buttons.
Instance Method Summary collapse
-
#initialize(type: 'text', name: 'input', placeholder: '', value: '', label: '', width: 'large', required: false, password_visible: true, custom_class: '', options: [], option_blank: false, disabled: false, multiple_files: false) ⇒ Cell
constructor
A new instance of Cell.
- #show ⇒ Object
Constructor Details
#initialize(type: 'text', name: 'input', placeholder: '', value: '', label: '', width: 'large', required: false, password_visible: true, custom_class: '', options: [], option_blank: false, disabled: false, multiple_files: false) ⇒ Cell
Returns a new instance of Cell.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'app/cells/lato_view/cells_v1/input/cell.rb', line 72 def initialize(type: 'text', name: 'input', placeholder: '', value: '', label: '', width: 'large', required: false, password_visible: true, custom_class: '', options: [], option_blank: false, disabled: false, multiple_files: false) # eseguo brevi controlli sull'input raise 'Input Concept: type has not a correct value' unless @@types.include? type raise 'Input Concept: width has not a correct value' unless @@widths.include? width raise 'Input Concept: options must be an array' if && !.is_a?(Array) # assegno i valori alle variabili di istanza @type = type @name = name @placeholder = placeholder @value = value @label = label @width = width @required = required @password_visible = password_visible = @custom_class = custom_class @option_blank = option_blank @disabled = disabled @multiple_files = multiple_files end |
Instance Attribute Details
#custom_class ⇒ Object
Classi custom da inserire nel codice dell’input
-
default: nil
50 51 52 |
# File 'app/cells/lato_view/cells_v1/input/cell.rb', line 50 def custom_class @custom_class end |
#disabled ⇒ Object
Valore che indica se disattivare o meno l’input
-
default: false
65 66 67 |
# File 'app/cells/lato_view/cells_v1/input/cell.rb', line 65 def disabled @disabled end |
#label ⇒ Object
Testo da inserire nella label dell’input
-
default: nil
32 33 34 |
# File 'app/cells/lato_view/cells_v1/input/cell.rb', line 32 def label @label end |
#multiple_files ⇒ Object
Valore che indica (nel caso di input file) se accettare piu’ file o uno singolarmente
-
default: false
70 71 72 |
# File 'app/cells/lato_view/cells_v1/input/cell.rb', line 70 def multiple_files @multiple_files end |
#name ⇒ Object
Nome da assegnare all’input
-
default: ‘input’
20 21 22 |
# File 'app/cells/lato_view/cells_v1/input/cell.rb', line 20 def name @name end |
#option_blank ⇒ Object
Valore booleano che indica (nel caso di input select) se mostrare o meno la prima opzione del select vuota
-
default: false
61 62 63 |
# File 'app/cells/lato_view/cells_v1/input/cell.rb', line 61 def option_blank @option_blank end |
#options ⇒ Object
Lista di opzioni da mostrare (nel caso di input select o radio buttons e checkbox). La struttura deve essere [[‘value1’, ‘Name 1’], [‘value2’, ‘Name 2’]]
-
default: []
56 57 58 |
# File 'app/cells/lato_view/cells_v1/input/cell.rb', line 56 def end |
#password_visible ⇒ Object
Valore booleano che indica (nel caso di input password) se mostrare il pulsante per vedere la password
-
default: true
46 47 48 |
# File 'app/cells/lato_view/cells_v1/input/cell.rb', line 46 def password_visible @password_visible end |
#placeholder ⇒ Object
Valore da inserire come placeholder all’input
-
default: nil
24 25 26 |
# File 'app/cells/lato_view/cells_v1/input/cell.rb', line 24 def placeholder @placeholder end |
#required ⇒ Object
Valore booleano usato per indicare se l’input e’ obbligatorio nel form in cui si trova
-
default: false
41 42 43 |
# File 'app/cells/lato_view/cells_v1/input/cell.rb', line 41 def required @required end |
#type ⇒ Object
Tipologia di input da inizializzare (text, number, select, password, email, multiple-select, date, checkbox, radio, textarea, file)
-
default: ‘text’
16 17 18 |
# File 'app/cells/lato_view/cells_v1/input/cell.rb', line 16 def type @type end |
#value ⇒ Object
Valore gia’ impostato nell’input
-
default: nil
28 29 30 |
# File 'app/cells/lato_view/cells_v1/input/cell.rb', line 28 def value @value end |
#width ⇒ Object
Dimensione dell’input (half, third, fourth, two-third)
-
default: nil (‘large’)
36 37 38 |
# File 'app/cells/lato_view/cells_v1/input/cell.rb', line 36 def width @width end |
Class Method Details
.generate_options_from_activerecords(activerecords, value, name) ⇒ Object
Funzione che prende in input un activerecords, il nome dell’attributo da usare come valore e il nome dell’attributo da usare come nome e ritorna un array da usare come options per un input select o un radio buttons
138 139 140 141 142 143 144 |
# File 'app/cells/lato_view/cells_v1/input/cell.rb', line 138 def self.(activerecords, value, name) rows = [] activerecords.each do |row| rows.push([row.send(value), row.send(name)]) end rows end |
Instance Method Details
#show ⇒ Object
97 98 99 |
# File 'app/cells/lato_view/cells_v1/input/cell.rb', line 97 def show render "#{@type.downcase}.html" if @type end |