glib-web 4.1.3 → 4.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/helpers/glib/json_ui/view_builder/fields.rb +2 -2
- data/app/helpers/glib/json_ui/view_builder/panels.rb +26 -16
- data/app/models/glib/dummy_job_application.rb +16 -0
- data/app/views/json_ui/garage/forms/text_validation.json.jbuilder +20 -27
- data/app/views/json_ui/garage/test_page/index.json.jbuilder +12 -4
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74c8034dd7dd38d81a358b836e90332f2cd1b9445a3a765de052141ee9c26aaf
|
4
|
+
data.tar.gz: 31f47b9867591f3459ddf8fbd14ca8e8ef7227c89ee9cea4edde81a7cefd710d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f39ee60b1d47d4b630940c039735f90cd729635d4cc8eeb93b0a1ede965dd52546d274748b9037fa0beee9129537a8282386fb424000730728b5c2023657a9c1
|
7
|
+
data.tar.gz: 9423dbc97f08201803f4bbf2f91fdaf5505124f402aa2d718405d29940824ab38bffbe09aeabf293c6ff657d42837564be463d5ffd828b70b180fe6581861cb9
|
@@ -66,7 +66,7 @@ class Glib::JsonUi::ViewBuilder
|
|
66
66
|
@label ||= context.field_label(@prop, @label_args || {})
|
67
67
|
@hint ||= context.hint_label(@prop, @hint_args || {})
|
68
68
|
@placeholder ||= context.placeholder_label(@prop, @placeholder_args || {})
|
69
|
-
@validation ||= context.field_validation(@prop)
|
69
|
+
@validation ||= context.field_validation(@prop) if @autoValidate
|
70
70
|
|
71
71
|
if form.current_dynamic_group.nil?
|
72
72
|
# This is not relevant inside a dynamic group
|
@@ -83,7 +83,7 @@ class Glib::JsonUi::ViewBuilder
|
|
83
83
|
# - Placeholder competes with label for space
|
84
84
|
json.placeholder @placeholder if @placeholder
|
85
85
|
|
86
|
-
json.validation @validation if @
|
86
|
+
json.validation @validation if @validation.present?
|
87
87
|
end
|
88
88
|
|
89
89
|
# To be overridden
|
@@ -118,35 +118,45 @@ class Glib::JsonUi::ViewBuilder
|
|
118
118
|
self.class.field_validation(@model, prop)
|
119
119
|
end
|
120
120
|
|
121
|
+
def self.lookup_error_message(model_name, attribute_name, key)
|
122
|
+
message = I18n.t("activerecord.errors.models.#{model_name}.attributes.#{attribute_name}.#{key}", default: nil) if model_name.present? && attribute_name.present?
|
123
|
+
message ||= I18n.t("activerecord.errors.models.#{model_name}.#{key}", default: nil) if model_name.present?
|
124
|
+
message ||= I18n.t("activerecord.errors.messages.#{key}", default: nil)
|
125
|
+
message ||= I18n.t("errors.attributes.#{attribute_name}.#{key}", default: nil) if attribute_name.present?
|
126
|
+
message ||= I18n.t("errors.messages.#{key}", default: nil)
|
127
|
+
message
|
128
|
+
end
|
129
|
+
|
121
130
|
def self.field_validation(model, prop)
|
122
131
|
validations = {}
|
132
|
+
ignored = ['confirmation', 'comparison', 'uniqueness', 'validates_associated', 'validates_each', 'validates_with', 'format']
|
123
133
|
model.class.validators_on(prop).each do |validator|
|
134
|
+
next if ignored.include?(validator.kind.to_s)
|
135
|
+
|
124
136
|
validations[validator.kind] = validator.options.except(:if, :unless)
|
125
137
|
validations[validator.kind][:message] = validator.options[:message]
|
126
138
|
case validator.kind
|
139
|
+
when :absence
|
140
|
+
validations[validator.kind][:message] ||= lookup_error_message(model.to_s.underscore, prop, 'present')
|
127
141
|
when :presence
|
128
|
-
validations[validator.kind][:message] ||=
|
142
|
+
validations[validator.kind][:message] ||= lookup_error_message(model.to_s.underscore, prop, 'blank')
|
129
143
|
when :acceptance
|
130
|
-
validations[validator.kind][:message] ||=
|
131
|
-
|
132
|
-
# raise NotImplemented
|
144
|
+
validations[validator.kind][:message] ||= lookup_error_message(model.to_s.underscore, prop, 'accepted')
|
145
|
+
validations[validator.kind][:accept] ||= ['1', true]
|
133
146
|
when :numericality
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
147
|
+
validations[validator.kind][:message] ||= [
|
148
|
+
'not_a_number', 'not_an_integer', 'greater_than',
|
149
|
+
'greater_than_or_equal_to', 'equal_to', 'less_than',
|
150
|
+
'less_than_or_equal_to', 'other_than', 'in', 'odd', 'even'
|
151
|
+
].inject({}) { |prev, curr| prev.merge(curr => lookup_error_message(model.to_s.underscore, prop, curr)) }
|
138
152
|
when :format
|
139
|
-
validations[validator.kind][:message] ||=
|
153
|
+
validations[validator.kind][:message] ||= lookup_error_message(model.to_s.underscore, prop, 'invalid')
|
140
154
|
when :inclusion
|
141
|
-
validations[validator.kind][:message] ||=
|
155
|
+
validations[validator.kind][:message] ||= lookup_error_message(model.to_s.underscore, prop, 'inclusion')
|
142
156
|
when :exclusion
|
143
|
-
validations[validator.kind][:message] ||=
|
157
|
+
validations[validator.kind][:message] ||= lookup_error_message(model.to_s.underscore, prop, 'exclusion')
|
144
158
|
when :length
|
145
|
-
validations[validator.kind][:message]
|
146
|
-
too_long: I18n.t('errors.messages.too_long'),
|
147
|
-
wrong_length: I18n.t('errors.messages.wrong_length'),
|
148
|
-
too_short: I18n.t('errors.messages.too_short')
|
149
|
-
}
|
159
|
+
validations[validator.kind][:message] ||= ['too_long', 'wrong_length', 'too_short'].inject({}) { |prev, curr| prev.merge(curr => lookup_error_message(model.to_s.underscore, prop, curr)) }
|
150
160
|
end
|
151
161
|
end
|
152
162
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Glib
|
2
|
+
class DummyJobApplication
|
3
|
+
include ActiveModel::Validations
|
4
|
+
include ActiveModel::AttributeMethods
|
5
|
+
|
6
|
+
attr_accessor :name, :age, :position, :words, :accept
|
7
|
+
|
8
|
+
validates :name, :position, presence: true
|
9
|
+
validates :accept, acceptance: {}, allow_nil: false
|
10
|
+
validates :words, length: { maximum: 100, minimum: 1 }
|
11
|
+
validates :age, numericality: { only_integer: true, less_than_or_equal_to: 30, greater_than_or_equal_to: 18 }, allow_blank: true
|
12
|
+
# validates :name, format: { with: /Doe/, message: 'This job is for person named Doe' }
|
13
|
+
validates :position, inclusion: { in: ['programmer', 'devops', 'designer'] }, allow_blank: true
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -4,15 +4,17 @@ page = json_ui_page json
|
|
4
4
|
render "#{@path_prefix}/nav_menu", json: json, page: page
|
5
5
|
|
6
6
|
page.form \
|
7
|
+
model: Glib::DummyJobApplication.new,
|
7
8
|
url: json_ui_garage_url(path: 'forms/generic_post'),
|
8
9
|
method: 'post',
|
9
10
|
padding: glib_json_padding_body,
|
10
11
|
childViews: ->(form) do
|
11
12
|
form.fields_text \
|
13
|
+
prop: :name,
|
12
14
|
name: 'user[name]',
|
13
15
|
width: 'matchParent',
|
14
16
|
label: 'Name',
|
15
|
-
validation: {
|
17
|
+
validation: { format: { regex: 'Doe', message: 'This job is only for person named Doe' } }
|
16
18
|
|
17
19
|
form.fields_email \
|
18
20
|
name: 'user[email]',
|
@@ -25,12 +27,11 @@ page.form \
|
|
25
27
|
label: 'URL'
|
26
28
|
|
27
29
|
form.fields_number \
|
28
|
-
|
30
|
+
prop: :age,
|
31
|
+
name: 'user[age]',
|
29
32
|
width: 'matchParent',
|
30
|
-
label: '
|
31
|
-
|
32
|
-
leftText: 'USD',
|
33
|
-
rightText: '.00'
|
33
|
+
label: 'Age',
|
34
|
+
autoValidate: true
|
34
35
|
|
35
36
|
form.fields_phone \
|
36
37
|
name: 'user[phone1]',
|
@@ -52,32 +53,21 @@ page.form \
|
|
52
53
|
leftIcon: 'lock'
|
53
54
|
|
54
55
|
form.fields_textarea \
|
55
|
-
|
56
|
+
prop: :words,
|
57
|
+
name: 'user[words]',
|
56
58
|
width: 'matchParent',
|
57
59
|
label: 'Textarea with maxLength',
|
58
|
-
maxLength:
|
59
|
-
|
60
|
-
|
61
|
-
# options = ['male', 'female'].map { |i| { text: i.humanize, value: i } }
|
62
|
-
# form.fields_select \
|
63
|
-
# name: 'user[gender]',
|
64
|
-
# width: 'matchParent',
|
65
|
-
# label: 'Gender',
|
66
|
-
# validation: { required: { message: 'Required' } },
|
67
|
-
# options: options
|
60
|
+
maxLength: 1000,
|
61
|
+
autoValidate: true
|
68
62
|
|
69
|
-
|
70
|
-
'brisbane' => 'Brisbane',
|
71
|
-
'canberra' => 'Canberra',
|
72
|
-
'melbourne' => 'Melbourne',
|
73
|
-
'sydney' => 'Sydney',
|
74
|
-
}
|
63
|
+
options = ['programmer', 'devops', 'designer', 'ceo', 'office_boy'].map { |v| { text: v.humanize, value: v } }
|
75
64
|
form.fields_select \
|
76
|
-
|
65
|
+
prop: :position,
|
66
|
+
name: 'user[position]',
|
77
67
|
width: 'matchParent',
|
78
|
-
label: '
|
79
|
-
options:
|
80
|
-
|
68
|
+
label: 'Position',
|
69
|
+
options: options,
|
70
|
+
autoValidate: true
|
81
71
|
|
82
72
|
form.spacer height: 10
|
83
73
|
form.h4 text: 'Gender'
|
@@ -104,6 +94,9 @@ page.form \
|
|
104
94
|
group.fields_check checkValue: 4, label: 'Mobile Development'
|
105
95
|
end
|
106
96
|
|
97
|
+
form.spacer height: 10
|
98
|
+
form.fields_check prop: :accept, label: 'Accept terms & condition', name: 'user[accept]', autoValidate: true
|
99
|
+
|
107
100
|
form.spacer height: 30
|
108
101
|
form.fields_submit text: 'Submit'
|
109
102
|
form.fields_submit text: 'Submit (disable if form invalid)', disableIfFormInvalid: true
|
@@ -5,13 +5,13 @@ page = json_ui_page json
|
|
5
5
|
page.body childViews: ->(body) do
|
6
6
|
body.panels_responsive padding: glib_json_padding_body, childViews: ->(res) do
|
7
7
|
res.panels_column lg: { cols: 6 }, childViews: ->(col) do
|
8
|
-
res.h2 text: 'Reactivity'
|
8
|
+
res.h2 text: 'Reactivity & validation'
|
9
9
|
res.spacer height: 8
|
10
10
|
res.panels_form \
|
11
11
|
url: json_ui_garage_url(path: 'forms/generic_post'),
|
12
12
|
method: 'post',
|
13
13
|
childViews: ->(form) do
|
14
|
-
form.
|
14
|
+
form.panels_flow innerPadding: { bottom: 0 }, width: 'matchParent', childViews: ->(hori) do
|
15
15
|
hori.button text: 'components/set', onClick: ->(action) do
|
16
16
|
action.runMultiple childActions: ->(saction) do
|
17
17
|
saction.components_set targetId: 'text', data: { value: 'Doe John' }
|
@@ -42,6 +42,10 @@ page.body childViews: ->(body) do
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
45
|
+
hori.spacer width: 4
|
46
|
+
hori.button text: 'hide select', onClick: ->(action) do
|
47
|
+
action.components_set targetId: 'select', data: { displayed: false }
|
48
|
+
end
|
45
49
|
end
|
46
50
|
|
47
51
|
form.spacer height: 8
|
@@ -53,7 +57,7 @@ page.body childViews: ->(body) do
|
|
53
57
|
|
54
58
|
form.fields_date width: 'matchParent', name: 'user[date]', id: 'date', value: Date.new(2024, 7, 24), validation: validation
|
55
59
|
form.hr width: 'matchParent'
|
56
|
-
form.fields_select multiple: true, width: 'matchParent', name: 'user[select]', id: 'select', options: options, value: ['option1', 'option2'], validation: validation
|
60
|
+
form.fields_select multiple: true, width: 'matchParent', name: 'user[select][]', id: 'select', options: options, value: ['option1', 'option2'], validation: validation
|
57
61
|
form.hr width: 'matchParent'
|
58
62
|
form.fields_chipGroup width: 'matchParent', name: 'user[chip_group]', id: 'chip_group', options: options, value: ['option2'], validation: validation
|
59
63
|
form.hr width: 'matchParent'
|
@@ -66,7 +70,7 @@ page.body childViews: ->(body) do
|
|
66
70
|
check_group_value = ['option3', 'option1']
|
67
71
|
form.fields_checkGroup width: 'matchParent', name: 'user[check_group]', id: 'check_group', value: check_group_value, validation: validation, childViews: ->(radio) do
|
68
72
|
options.each do |option|
|
69
|
-
radio.fields_check label: option['text'],
|
73
|
+
radio.fields_check label: option['text'], checkValue: option['value']
|
70
74
|
end
|
71
75
|
end
|
72
76
|
form.hr width: 'matchParent'
|
@@ -100,6 +104,10 @@ page.body childViews: ->(body) do
|
|
100
104
|
ssaction.dialogs_show updateExisting: true, disableCloseButton: true, content: ->(sdialog) do
|
101
105
|
sdialog.body padding: glib_json_padding_body, childViews: ->(ssbody) do
|
102
106
|
ssbody.h1 text: 'Hello world (updated)'
|
107
|
+
ssbody.spacer height: 8
|
108
|
+
ssbody.button text: 'close', onClick: ->(xaction) do
|
109
|
+
xaction.dialogs_close
|
110
|
+
end
|
103
111
|
end
|
104
112
|
end
|
105
113
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glib-web
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.1.
|
4
|
+
version: 4.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ''
|
@@ -134,6 +134,7 @@ files:
|
|
134
134
|
- app/models/glib/active_storage/attachment.rb
|
135
135
|
- app/models/glib/active_storage/blob.rb
|
136
136
|
- app/models/glib/application_record.rb
|
137
|
+
- app/models/glib/dummy_job_application.rb
|
137
138
|
- app/models/glib/dynamic_text_record.rb
|
138
139
|
- app/models/glib/text.rb
|
139
140
|
- app/policies/glib/application_policy.rb
|