Class: Forma::TextField

Inherits:
SimpleField show all
Defined in:
lib/forma/field.rb

Overview

Text field.

Direct Known Subclasses

EmailField, NumberField

Instance Attribute Summary collapse

Attributes inherited from Field

#actions, #after, #autofocus, #before, #child_model_name, #height, #hint, #i18n, #icon, #inline_hint, #label, #model, #model_name, #name, #parent, #readonly, #required, #tag, #url, #value, #width

Instance Method Summary collapse

Methods inherited from SimpleField

#errors, #has_errors?, #value

Methods inherited from Field

#action, #id, #localization_key, #localized_hint, #localized_label, #name_as_chain, #parameter_name, #to_html

Methods included from Html

attr, el

Methods included from Utils

extract_value, number_format, #simple_value, singular_name

Constructor Details

#initialize(h = {}) ⇒ TextField

Returns a new instance of TextField.



294
295
296
297
298
# File 'lib/forma/field.rb', line 294

def initialize(h = {})
  h = h.symbolize_keys
  @password = h[:password]
  super(h)
end

Instance Attribute Details

#passwordObject (readonly)

Returns the value of attribute password.



292
293
294
# File 'lib/forma/field.rb', line 292

def password
  @password
end

Instance Method Details

#edit_element(val) ⇒ Object



304
305
306
307
308
309
310
311
312
313
# File 'lib/forma/field.rb', line 304

def edit_element(val)
  el('input', attrs: {
    id: self.id,
    name: parameter_name,
    type: (password ? 'password' : 'text'),
    value: val.to_s,
    autofocus: @autofocus,
    style: { width: ("#{width}px" if width.present?) }
  })
end

#view_element(val) ⇒ Object



300
301
302
# File 'lib/forma/field.rb', line 300

def view_element(val)
  el((@tag || 'span'), text: (password ? '******' : val.to_s), attrs: { id: self.id })
end