Class: Voom::Presenters::DSL::Components::TextField

Inherits:
Input show all
Defined in:
lib/voom/presenters/dsl/components/text_field.rb

Direct Known Subclasses

DatetimeBase, NumberField, RichTextArea, TextArea

Constant Summary collapse

VALID_CASE_TYPES =
%i[mixed upper lower].freeze

Instance Attribute Summary collapse

Attributes inherited from Input

#dirtyable, #disabled, #name

Attributes inherited from EventBase

#event_parent_id

Attributes included from Mixins::Event

#events

Attributes inherited from Base

#attributes, #css_class, #draggable, #drop_zone, #id, #tag, #type

Instance Method Summary collapse

Methods inherited from Input

#validation_error

Methods included from Mixins::Tooltips

#tooltip

Methods included from Mixins::Event

#event

Methods inherited from Base

#expand!

Methods included from Pluggable

#include_plugins, #plugin, #plugin_module

Methods included from Mixins::YieldTo

#yield_to

Methods included from Serializer

#to_hash

Methods included from Lockable

#locked?

Constructor Details

#initialize(**attribs_, &block) ⇒ TextField

Returns a new instance of TextField.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/voom/presenters/dsl/components/text_field.rb', line 15

def initialize(**attribs_, &block)
  super(type: :text_field, **attribs_, &block)
  @required = attribs.delete(:required){ false }
  @full_width = attribs.delete(:full_width){ true }
  @case_type = validate_case_type(attribs.delete(:case_type) { :mixed })
  @auto_complete = validate_auto_complete(attribs.delete(:auto_complete) { :off })
  @behavior = determine_behavior(attribs.delete(:password), attribs.delete(:behavior))
  label(attribs.delete(:label))if attribs.key?(:label)
  value(attribs.delete(:value))if attribs.key?(:value)
  expand!
end

Instance Attribute Details

#auto_completeObject (readonly)

Returns the value of attribute auto_complete.



7
8
9
# File 'lib/voom/presenters/dsl/components/text_field.rb', line 7

def auto_complete
  @auto_complete
end

#behaviorObject (readonly)

Returns the value of attribute behavior.



7
8
9
# File 'lib/voom/presenters/dsl/components/text_field.rb', line 7

def behavior
  @behavior
end

#case_typeObject (readonly)

Returns the value of attribute case_type.



7
8
9
# File 'lib/voom/presenters/dsl/components/text_field.rb', line 7

def case_type
  @case_type
end

#full_widthObject (readonly)

Returns the value of attribute full_width.



7
8
9
# File 'lib/voom/presenters/dsl/components/text_field.rb', line 7

def full_width
  @full_width
end

#requiredObject (readonly)

Returns the value of attribute required.



7
8
9
# File 'lib/voom/presenters/dsl/components/text_field.rb', line 7

def required
  @required
end

Instance Method Details

#hint(hint = nil) ⇒ Object



48
49
50
51
# File 'lib/voom/presenters/dsl/components/text_field.rb', line 48

def hint(hint=nil)
  return @hint if locked?
  @hint = hint
end

#icon(icon = nil, **attribs, &block) ⇒ Object



32
33
34
35
36
# File 'lib/voom/presenters/dsl/components/text_field.rb', line 32

def icon(icon=nil, **attribs, &block)
  return @icon if locked?
  @icon = Components::Icon.new(parent: self, icon: icon, position: attribs.delete(:position){:right},
                               **attribs, &block)
end

#label(text = nil) ⇒ Object



27
28
29
30
# File 'lib/voom/presenters/dsl/components/text_field.rb', line 27

def label(text=nil)
  return @label if locked?
  @label = text
end

#pattern(pattern = nil) ⇒ Object



43
44
45
46
# File 'lib/voom/presenters/dsl/components/text_field.rb', line 43

def pattern(pattern=nil)
  return @pattern if locked?
  @pattern = json_regexp(Regexp.new(pattern))
end

#value(value = nil) ⇒ Object



38
39
40
41
# File 'lib/voom/presenters/dsl/components/text_field.rb', line 38

def value(value=nil)
  return @value if locked?
  @value = value
end