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 JsonUiElement

#initialize, #props

Constructor Details

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

Instance Method Details

#createdObject

Override



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 48

def created
  if @prop && (form = page.current_form)
    form.field_assert_respond_to(@prop)

    @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 || {})

    @validation ||= form.field_validation(@prop)
  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

  # TODO: Add a flag so the framework's user can turn it on and off.
  # json.validation @validation if @validation
end

#hint(hint) ⇒ Object



19
20
21
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 19

def hint(hint)
  @hint = hint
end

#hint_args(hint_args) ⇒ Object



23
24
25
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 23

def hint_args(hint_args)
  @hint_args = hint_args
end

#label(label) ⇒ Object



11
12
13
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 11

def label(label)
  @label = label
end

#label_args(label_args) ⇒ Object



15
16
17
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 15

def label_args(label_args)
  @label_args = label_args
end

#name(name) ⇒ Object



35
36
37
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 35

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

#placeholder(placeholder) ⇒ Object



27
28
29
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 27

def placeholder(placeholder)
  @placeholder = placeholder
end

#placeholder_args(placeholder_args) ⇒ Object



31
32
33
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 31

def placeholder_args(placeholder_args)
  @placeholder_args = placeholder_args
end

#prop(prop) ⇒ Object



43
44
45
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 43

def prop(prop)
  @prop = prop
end

#value(value) ⇒ Object



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

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