Class: OkonomiUiKit::Components::Forms::InputBase
Direct Known Subclasses
DateField, DatetimeLocalField, EmailField, NumberField, PasswordField, SearchField, TelephoneField, TextArea, TextField, TimeField, UrlField
Instance Attribute Summary
#view
Class Method Summary
collapse
Instance Method Summary
collapse
namespace
#combined_styles, config_class?, config_class_name, config_classes, config_namespace, #config_styles_registry, config_styles_registry, deep_merge, #initialize, #internal_styles_registry, internal_styles_registry, #name, parent_styles_registry, register_styles, resolve_config_classes, #style, #styles, #template_path, #theme_name, #tw_merge, #variant_style
Class Method Details
.type(type) ⇒ Object
19
20
21
|
# File 'app/helpers/okonomi_ui_kit/components/forms/input_base.rb', line 19
def self.type(type)
@type = type
end
|
.type_value ⇒ Object
23
24
25
|
# File 'app/helpers/okonomi_ui_kit/components/forms/input_base.rb', line 23
def self.type_value
@type || :text
end
|
Instance Method Details
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'app/helpers/okonomi_ui_kit/components/forms/input_base.rb', line 27
def input_field_classes(object, method, type, options, include_disabled: true)
css_classes = OkonomiUiKit::TWMerge.merge_all(
style(:root),
when_errors(
object,
method,
style(:error),
style(:valid)
),
options[:class]
)
if include_disabled
css_classes = OkonomiUiKit::TWMerge.merge_all(css_classes, style(:disabled))
end
css_classes
end
|
#render_arguments(object, method, options = {}) ⇒ Object
5
6
7
8
|
# File 'app/helpers/okonomi_ui_kit/components/forms/input_base.rb', line 5
def render_arguments(object, method, options = {})
css = input_field_classes(object, method, self.class.type_value, options)
[ method, { autocomplete: "off" }.merge(options).merge(class: css) ]
end
|
#when_errors(object, method, value, default_value = nil) ⇒ Object
46
47
48
49
50
51
52
53
|
# File 'app/helpers/okonomi_ui_kit/components/forms/input_base.rb', line 46
def when_errors(object, method, value, default_value = nil)
key = method.to_s.gsub("_id", "").to_sym
if object.errors.include?(key) || object.errors.include?(method)
value
else
default_value
end
end
|