Class: Glib::JsonUi::ViewBuilder::Fields::AbstractField

Inherits:
View show all
Defined in:
app/helpers/glib/json_ui/view_builder/fields.rb

Instance Attribute Summary

Attributes inherited from JsonUiElement

#json, #page

Instance Method Summary collapse

Methods inherited from View

#analytics

Methods inherited from JsonUiElement

#initialize, #parse

Constructor Details

This class inherits a constructor from Glib::JsonUi::JsonUiElement

Instance Method Details

#createdObject

Override



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 46

def created
  if (@prop && form = page.current_form)
    @name ||= form.field_name(@prop, @multiple || false)
    @value ||= form.field_value(@prop)
    @label ||= form.field_label(@prop, @label_args || {})
    @hint ||= form.hint_label(@prop, @hint_args || {})
    @placeholder ||= form.placeholder_label(@prop, @placeholder_args || {})
  end
  json.name @name
  json.value @value if @value
  json.label @label if @label
  json.hint @hint if @hint

  # In general, use hint over placeholder for the following reasons:
  # - Placeholder gets hidden when there is input which may be confusing
  # - Placeholder competes with label for space
  json.placeholder @placeholder if @placeholder
end

#hint(hint) ⇒ Object



13
14
15
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 13

def hint(hint)
  @hint = hint
end

#hint_args(hint_args) ⇒ Object



17
18
19
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 17

def hint_args(hint_args)
  @hint_args = hint_args
end

#label(label) ⇒ Object



5
6
7
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 5

def label(label)
  @label = label
end

#label_args(label_args) ⇒ Object



9
10
11
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 9

def label_args(label_args)
  @label_args = label_args
end

#name(name) ⇒ Object



29
30
31
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 29

def name(name)
  @name = name if name != Glib::Value::DEFAULT
end

#placeholder(placeholder) ⇒ Object



21
22
23
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 21

def placeholder(placeholder)
  @placeholder = placeholder
end

#placeholder_args(placeholder_args) ⇒ Object



25
26
27
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 25

def placeholder_args(placeholder_args)
  @placeholder_args = placeholder_args
end

#prop(prop) ⇒ Object



37
38
39
40
41
42
43
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 37

def prop(prop)
  @prop = prop
  # if (form = page.current_form)
  #   @name ||= form.field_name(prop)
  #   @value ||= form.field_value(prop)
  # end
end

#value(value) ⇒ Object



33
34
35
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 33

def value(value)
  @value = value if value != Glib::Value::DEFAULT
end