Class: Matestack::Ui::Bootstrap::Form::Input

Inherits:
Core::Form::Input::Input
  • Object
show all
Defined in:
app/concepts/matestack/ui/bootstrap/form/input.rb

Instance Method Summary collapse

Instance Method Details

#bootstrap_file_input_attributesObject



65
66
67
68
69
70
# File 'app/concepts/matestack/ui/bootstrap/form/input.rb', line 65

def bootstrap_file_input_attributes
  {
    class: (options[:class] || "") << (" form-file-input"),
    disabled: disabled
  }
end

#bootstrap_input_attributesObject



48
49
50
51
52
53
# File 'app/concepts/matestack/ui/bootstrap/form/input.rb', line 48

def bootstrap_input_attributes
  {
    class: (options[:class] || "") << (" form-control"),
    disabled: disabled
  }
end

#bootstrap_range_attributesObject



55
56
57
58
59
60
61
62
63
# File 'app/concepts/matestack/ui/bootstrap/form/input.rb', line 55

def bootstrap_range_attributes
  {
    class: (options[:class] || "") << (" form-range"),
    disabled: disabled,
    min: min,
    max: max,
    steps: step
  }
end

#file_inputObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/concepts/matestack/ui/bootstrap/form/input.rb', line 83

def file_input
  div class: form_file_wrapper_class do
    input html_attributes.merge(attributes: vue_attributes).merge(bootstrap_file_input_attributes)
    label class: "form-file-label", for: attr_key do
      span class: "form-file-text", attributes: { "v-if": "data['#{attr_key}']" } do
        if multiple
          span attributes: { "v-for": "file in data['#{attr_key}']" } do
            plain "{{ file['name'] }}"
          end
        else
          plain "{{ data['#{attr_key}']['name'] }}"
        end
      end
      span class: "form-file-text", attributes: { "v-if": "!data['#{attr_key}']" } do
        plain placeholder || "Choose file"
      end
      span class: "form-file-button", text: browse_button_text || "Browse"
    end
    render_errors
  end
end

#form_file_wrapper_classObject



72
73
74
75
76
77
78
79
80
81
# File 'app/concepts/matestack/ui/bootstrap/form/input.rb', line 72

def form_file_wrapper_class
  case variant
  when :lg
    (options[:class] || "") << (" form-file form-file-lg")
  when :sm
    (options[:class] || "") << (" form-file form-file-sm")
  else
    (options[:class] || "") << (" form-file")
  end
end

#input_error_classObject



113
114
115
# File 'app/concepts/matestack/ui/bootstrap/form/input.rb', line 113

def input_error_class
  'is-invalid'
end

#render_errorsObject



105
106
107
108
109
110
111
# File 'app/concepts/matestack/ui/bootstrap/form/input.rb', line 105

def render_errors
  unless @included_config[:errors] == false && (errors == false || errors.nil?) || errors == false
    div class: 'invalid-feedback', attributes: { 'v-for': "error in #{error_key}" } do
      plain '{{ error }}'
    end
  end
end

#render_form_textObject



117
118
119
120
121
# File 'app/concepts/matestack/ui/bootstrap/form/input.rb', line 117

def render_form_text
  div id: "form_text_for_#{attr_key}", class: "form-text" do
    plain form_text
  end
end

#responseObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/concepts/matestack/ui/bootstrap/form/input.rb', line 13

def response
  div do
    label for: attr_key,  class: "form-label", text: input_label if input_label
    case type
    when :range
      input html_attributes.merge(attributes: vue_attributes).merge(bootstrap_range_attributes)
      if show_value
        div id: attr_key, class: "form-text" do
          plain "{{ data['#{attr_key}'] }}"
        end
      end
    when :file
      file_input
    else
      input html_attributes.merge(attributes: vue_attributes).merge(bootstrap_input_attributes)
      render_errors
    end
    render_form_text if form_text
  end
end

#vue_attributesObject



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/concepts/matestack/ui/bootstrap/form/input.rb', line 34

def vue_attributes
  (options[:attributes] || {}).merge({
    id: attr_key,
    "@change": change_event,
    ref: "input.#{attr_key}",
    'init-value': init_value,
    'v-bind:class': "{ '#{input_error_class}': #{error_key} }",
    "aria-describedby": attr_key,
    "step": "any"
  }).merge(
    type != :file ? { "#{v_model_type}": input_key } : {}
  ) # file inputs are readonly, no v-model possible
end