not-bulma 1.2.67 → 1.2.69
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.
package/package.json
CHANGED
|
@@ -1,246 +1,280 @@
|
|
|
1
|
-
import notCommon from
|
|
1
|
+
import notCommon from "../../common";
|
|
2
2
|
|
|
3
3
|
const DEFAULT_FIELD = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
label: "",
|
|
5
|
+
placeholder: "",
|
|
6
|
+
enabled: true,
|
|
7
|
+
visible: true,
|
|
8
|
+
required: true,
|
|
9
|
+
validated: false,
|
|
10
|
+
valid: false,
|
|
11
|
+
errors: false,
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* Creates field manifest
|
|
16
|
-
* @param {string} type name/type of the field
|
|
17
|
-
* @param {Object} mutation mutation to manifest from library
|
|
18
|
-
* @param {Object} VARIANTS store which contains named lists of field value variants
|
|
19
|
-
* @param {Object} FIELDS store which contains named lists of field manifests
|
|
20
|
-
* @return {Object} field manifest
|
|
21
|
-
**/
|
|
15
|
+
* Creates field manifest
|
|
16
|
+
* @param {string} type name/type of the field
|
|
17
|
+
* @param {Object} mutation mutation to manifest from library
|
|
18
|
+
* @param {Object} VARIANTS store which contains named lists of field value variants
|
|
19
|
+
* @param {Object} FIELDS store which contains named lists of field manifests
|
|
20
|
+
* @return {Object} field manifest
|
|
21
|
+
**/
|
|
22
22
|
function fieldInit(type, mutation = {}, VARIANTS, FIELDS) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
//adding mutations
|
|
32
|
-
if (mutation) {
|
|
33
|
-
field = {
|
|
34
|
-
...field,
|
|
35
|
-
...mutation
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
//adding variants list to field from VARIANTS store
|
|
39
|
-
if (
|
|
40
|
-
notCommon.objHas(field, 'variantsSource') &&
|
|
41
|
-
VARIANTS.contains(field.variantsSource)
|
|
42
|
-
) {
|
|
43
|
-
field.variants = VARIANTS.get(field.variantsSource);
|
|
44
|
-
}else{
|
|
45
|
-
if(!field.variants || field.variants.length === 0 ){
|
|
46
|
-
field.variants = [];
|
|
23
|
+
let field = { ...DEFAULT_FIELD };
|
|
24
|
+
//getting field core manifest
|
|
25
|
+
if (FIELDS.contains(type)) {
|
|
26
|
+
field = {
|
|
27
|
+
...field,
|
|
28
|
+
...FIELDS.get(type),
|
|
29
|
+
};
|
|
47
30
|
}
|
|
48
|
-
|
|
49
|
-
|
|
31
|
+
//adding mutations
|
|
32
|
+
if (mutation) {
|
|
33
|
+
field = {
|
|
34
|
+
...field,
|
|
35
|
+
...mutation,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//adding variants list to field from VARIANTS store
|
|
39
|
+
if (
|
|
40
|
+
notCommon.objHas(field, "variantsSource") &&
|
|
41
|
+
VARIANTS.contains(field.variantsSource)
|
|
42
|
+
) {
|
|
43
|
+
field.variants = VARIANTS.get(field.variantsSource);
|
|
44
|
+
} else {
|
|
45
|
+
if (!field.variants || field.variants.length === 0) {
|
|
46
|
+
field.variants = [];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return field;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
|
-
* Initialization of form structure object
|
|
54
|
-
* @param {object} form form structure object
|
|
55
|
-
* @param {string|Array<string>} fieldName name of the field type if string, array of strings = subform
|
|
56
|
-
* @param {Object} VARIANTS store which contains named lists of field value variants
|
|
57
|
-
* @param {Object} FIELDS store which contains named lists of field manifests
|
|
58
|
-
* @param {Object} formFieldsOptions form wide options
|
|
59
|
-
* @returns {Object} form structure object
|
|
60
|
-
**/
|
|
61
|
-
function initFormByField(
|
|
62
|
-
|
|
63
|
-
fieldName
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
53
|
+
* Initialization of form structure object
|
|
54
|
+
* @param {object} form form structure object
|
|
55
|
+
* @param {string|Array<string>} fieldName name of the field type if string, array of strings = subform
|
|
56
|
+
* @param {Object} VARIANTS store which contains named lists of field value variants
|
|
57
|
+
* @param {Object} FIELDS store which contains named lists of field manifests
|
|
58
|
+
* @param {Object} formFieldsOptions form wide options
|
|
59
|
+
* @returns {Object} form structure object
|
|
60
|
+
**/
|
|
61
|
+
function initFormByField(
|
|
62
|
+
form = {},
|
|
63
|
+
fieldName = [],
|
|
64
|
+
VARIANTS,
|
|
65
|
+
FIELDS,
|
|
66
|
+
formFieldsOptions,
|
|
67
|
+
data
|
|
68
|
+
) {
|
|
69
|
+
if (Array.isArray(fieldName)) {
|
|
70
|
+
fieldName.forEach((subFormFieldName) =>
|
|
71
|
+
initFormByField(
|
|
72
|
+
form,
|
|
73
|
+
subFormFieldName,
|
|
74
|
+
VARIANTS,
|
|
75
|
+
FIELDS,
|
|
76
|
+
formFieldsOptions,
|
|
77
|
+
data
|
|
78
|
+
)
|
|
79
|
+
);
|
|
80
|
+
} else {
|
|
81
|
+
let opts = {};
|
|
82
|
+
if (
|
|
83
|
+
formFieldsOptions &&
|
|
84
|
+
notCommon.objHas(formFieldsOptions, "mutations") &&
|
|
85
|
+
notCommon.objHas(formFieldsOptions.mutations, fieldName)
|
|
86
|
+
) {
|
|
87
|
+
opts = formFieldsOptions.mutations[fieldName]; //option mutation for field
|
|
88
|
+
}
|
|
89
|
+
if (data && notCommon.objHas(data, fieldName)) {
|
|
90
|
+
opts.value = data[fieldName];
|
|
91
|
+
}
|
|
92
|
+
form[fieldName] = fieldInit(fieldName, opts, VARIANTS, FIELDS);
|
|
93
|
+
//if form readonly, marking every field as readonly
|
|
94
|
+
if (formFieldsOptions && formFieldsOptions.readonly) {
|
|
95
|
+
form[fieldName].readonly = true;
|
|
96
|
+
}
|
|
76
97
|
}
|
|
77
|
-
|
|
78
|
-
return form;
|
|
98
|
+
return form;
|
|
79
99
|
}
|
|
80
100
|
|
|
81
101
|
/**
|
|
82
|
-
* Marking field as invalid by own validator
|
|
83
|
-
* @param {Object} form form structure object
|
|
84
|
-
* @param {string} fieldName name of the field
|
|
85
|
-
* @param {any} value value of field
|
|
86
|
-
* @param {Array<string>} errors list of errors
|
|
87
|
-
* @return {Object} form structure object
|
|
88
|
-
**/
|
|
102
|
+
* Marking field as invalid by own validator
|
|
103
|
+
* @param {Object} form form structure object
|
|
104
|
+
* @param {string} fieldName name of the field
|
|
105
|
+
* @param {any} value value of field
|
|
106
|
+
* @param {Array<string>} errors list of errors
|
|
107
|
+
* @return {Object} form structure object
|
|
108
|
+
**/
|
|
89
109
|
function setFieldInvalid(form, fieldName, value, errors) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
110
|
+
form[fieldName].errors = [...errors];
|
|
111
|
+
form[fieldName].validated = true;
|
|
112
|
+
form[fieldName].valid = false;
|
|
113
|
+
form[fieldName].value = value;
|
|
114
|
+
return form;
|
|
95
115
|
}
|
|
96
116
|
|
|
97
117
|
/**
|
|
98
|
-
* Marking field as valid by own validator
|
|
99
|
-
* @param {Object} form form structure object
|
|
100
|
-
* @param {string} fieldName name of the field
|
|
101
|
-
* @param {any} value value of field
|
|
102
|
-
* @return {Object} form structure object
|
|
103
|
-
**/
|
|
118
|
+
* Marking field as valid by own validator
|
|
119
|
+
* @param {Object} form form structure object
|
|
120
|
+
* @param {string} fieldName name of the field
|
|
121
|
+
* @param {any} value value of field
|
|
122
|
+
* @return {Object} form structure object
|
|
123
|
+
**/
|
|
104
124
|
function setFieldValid(form, fieldName, value) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
125
|
+
form[fieldName].errors = false;
|
|
126
|
+
form[fieldName].validated = true;
|
|
127
|
+
form[fieldName].valid = true;
|
|
128
|
+
form[fieldName].value = value;
|
|
129
|
+
let some = false;
|
|
130
|
+
for (let fname in form) {
|
|
131
|
+
if (fname !== fieldName) {
|
|
132
|
+
if (
|
|
133
|
+
Array.isArray(form[fname].errors) &&
|
|
134
|
+
form[fname].errors.length === 0
|
|
135
|
+
) {
|
|
136
|
+
form[fname].errors = false;
|
|
137
|
+
}
|
|
138
|
+
if (form[fname].errors !== false) {
|
|
139
|
+
some = true;
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
119
143
|
}
|
|
120
|
-
|
|
121
|
-
return form;
|
|
144
|
+
return form;
|
|
122
145
|
}
|
|
123
146
|
|
|
124
147
|
/**
|
|
125
|
-
* Checks if field has errors
|
|
126
|
-
* @param {Object} form form structure object
|
|
127
|
-
* @param {string} fieldName name of the field
|
|
128
|
-
* @returns {boolean} true - valid, false -invalid
|
|
129
|
-
**/
|
|
148
|
+
* Checks if field has errors
|
|
149
|
+
* @param {Object} form form structure object
|
|
150
|
+
* @param {string} fieldName name of the field
|
|
151
|
+
* @returns {boolean} true - valid, false -invalid
|
|
152
|
+
**/
|
|
130
153
|
function isFieldValid(form, fieldName) {
|
|
131
|
-
|
|
154
|
+
return !Array.isArray(form[fieldName].errors);
|
|
132
155
|
}
|
|
133
156
|
|
|
134
157
|
/**
|
|
135
|
-
* Form level validator error in this field
|
|
136
|
-
* @param {Object} form form structure object
|
|
137
|
-
* @param {string} fieldName name of the field
|
|
138
|
-
* @param {Array<string>} errors list of errors
|
|
139
|
-
* @return {Object} form structure object
|
|
140
|
-
**/
|
|
158
|
+
* Form level validator error in this field
|
|
159
|
+
* @param {Object} form form structure object
|
|
160
|
+
* @param {string} fieldName name of the field
|
|
161
|
+
* @param {Array<string>} errors list of errors
|
|
162
|
+
* @return {Object} form structure object
|
|
163
|
+
**/
|
|
141
164
|
function setFormFieldInvalid(form, fieldName, errors) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
165
|
+
form[fieldName].formErrors = [...errors];
|
|
166
|
+
form[fieldName].validated = true;
|
|
167
|
+
form[fieldName].inputStarted = true;
|
|
168
|
+
form[fieldName].valid = false;
|
|
169
|
+
form[fieldName].formLevelError = true;
|
|
170
|
+
return form;
|
|
148
171
|
}
|
|
149
172
|
/**
|
|
150
|
-
* Form level validator success in this field
|
|
151
|
-
* @param {Object} form form structure object
|
|
152
|
-
* @param {string} fieldName name of the field
|
|
153
|
-
* @return {Object} form structure object
|
|
154
|
-
**/
|
|
173
|
+
* Form level validator success in this field
|
|
174
|
+
* @param {Object} form form structure object
|
|
175
|
+
* @param {string} fieldName name of the field
|
|
176
|
+
* @return {Object} form structure object
|
|
177
|
+
**/
|
|
155
178
|
function setFormFieldValid(form, fieldName) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
179
|
+
form[fieldName].formErrors = false;
|
|
180
|
+
form[fieldName].validated = true;
|
|
181
|
+
form[fieldName].valid = true;
|
|
182
|
+
form[fieldName].formLevelError = false;
|
|
183
|
+
return form;
|
|
161
184
|
}
|
|
162
185
|
|
|
163
186
|
/**
|
|
164
|
-
* Updates fields and form error labels
|
|
165
|
-
* @param {Object} form form structure object
|
|
166
|
-
* @param {Object} validationStatus results of validation
|
|
167
|
-
**/
|
|
187
|
+
* Updates fields and form error labels
|
|
188
|
+
* @param {Object} form form structure object
|
|
189
|
+
* @param {Object} validationStatus results of validation
|
|
190
|
+
**/
|
|
168
191
|
function updateFormValidationStatus(
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
192
|
+
{
|
|
193
|
+
form,
|
|
194
|
+
formErrors,
|
|
195
|
+
formHasErrors,
|
|
196
|
+
fieldsHasErrors,
|
|
197
|
+
validationStatus,
|
|
198
|
+
} /* FormValidationSession.getCompleteResult() */
|
|
176
199
|
) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
200
|
+
formHasErrors = false;
|
|
201
|
+
fieldsHasErrors = false;
|
|
202
|
+
if (Array.isArray(validationStatus.form) && validationStatus.form.length) {
|
|
203
|
+
formErrors.splice(0, formErrors.length, ...validationStatus.form);
|
|
204
|
+
formHasErrors = true;
|
|
205
|
+
} else {
|
|
206
|
+
formErrors.splice(0, formErrors.length);
|
|
207
|
+
}
|
|
208
|
+
formErrors = formErrors;
|
|
209
|
+
if (validationStatus.fields) {
|
|
210
|
+
for (let fieldName in validationStatus.fields) {
|
|
211
|
+
if (
|
|
212
|
+
Array.isArray(validationStatus.fields[fieldName]) &&
|
|
213
|
+
validationStatus.fields[fieldName].length
|
|
214
|
+
) {
|
|
215
|
+
setFormFieldInvalid(
|
|
216
|
+
form,
|
|
217
|
+
fieldName,
|
|
218
|
+
validationStatus.fields[fieldName]
|
|
219
|
+
);
|
|
220
|
+
fieldsHasErrors = true;
|
|
221
|
+
} else {
|
|
222
|
+
setFormFieldValid(form, fieldName);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
194
225
|
}
|
|
195
|
-
}
|
|
196
226
|
}
|
|
197
227
|
|
|
198
228
|
function setFieldsVisibility(form, fieldsList, val) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
229
|
+
if (Array.isArray(fieldsList)) {
|
|
230
|
+
Object.keys(form).forEach((fieldName) => {
|
|
231
|
+
form[fieldName].visible = fieldsList.includes(fieldName)
|
|
232
|
+
? val
|
|
233
|
+
: !val;
|
|
234
|
+
});
|
|
235
|
+
return true;
|
|
236
|
+
}
|
|
237
|
+
return false;
|
|
206
238
|
}
|
|
207
239
|
|
|
208
240
|
function setFieldValue(form, fieldName, value) {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
241
|
+
if (notCommon.objHas(form, fieldName)) {
|
|
242
|
+
form[fieldName].value = value;
|
|
243
|
+
return true;
|
|
244
|
+
}
|
|
245
|
+
return false;
|
|
214
246
|
}
|
|
215
247
|
|
|
216
|
-
function fieldIsVisibleAndFilled(form, fieldName){
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
248
|
+
function fieldIsVisibleAndFilled(form, fieldName) {
|
|
249
|
+
return (
|
|
250
|
+
notCommon.objHas(form, fieldName) &&
|
|
251
|
+
form[fieldName].enabled &&
|
|
252
|
+
form[fieldName].visible &&
|
|
253
|
+
typeof form[fieldName].value !== "undefined"
|
|
254
|
+
);
|
|
221
255
|
}
|
|
222
256
|
|
|
223
257
|
function collectData(fields, form) {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
258
|
+
let result = {};
|
|
259
|
+
fields.flat().forEach((fieldName) => {
|
|
260
|
+
if (fieldIsVisibleAndFilled(form, fieldName)) {
|
|
261
|
+
result[fieldName] = form[fieldName].value;
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
return result;
|
|
231
265
|
}
|
|
232
266
|
|
|
233
267
|
export default {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
268
|
+
fieldInit,
|
|
269
|
+
initFormByField,
|
|
270
|
+
setFieldInvalid,
|
|
271
|
+
setFieldValid,
|
|
272
|
+
isFieldValid,
|
|
273
|
+
setFormFieldInvalid,
|
|
274
|
+
setFormFieldValid,
|
|
275
|
+
updateFormValidationStatus,
|
|
276
|
+
fieldIsVisibleAndFilled,
|
|
277
|
+
setFieldsVisibility,
|
|
278
|
+
setFieldValue,
|
|
279
|
+
collectData,
|
|
246
280
|
};
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
export let WAITING_TEXT = "Отправка данных на сервер";
|
|
48
48
|
|
|
49
49
|
//form labels
|
|
50
|
-
export let title = "
|
|
50
|
+
export let title = "";
|
|
51
51
|
export let description = "";
|
|
52
52
|
//if you want button on top
|
|
53
53
|
export let buttonsFirst = false;
|
|
@@ -219,7 +219,6 @@
|
|
|
219
219
|
{#if description}
|
|
220
220
|
<h6 class="subtitle is-6">{$LOCALE[description]}</h6>
|
|
221
221
|
{/if}
|
|
222
|
-
|
|
223
222
|
{#if buttonsFirst}
|
|
224
223
|
<div class="buttons is-grouped is-centered">
|
|
225
224
|
{#if cancel.enabled}
|
|
@@ -37,7 +37,11 @@
|
|
|
37
37
|
export let helpers = {};
|
|
38
38
|
</script>
|
|
39
39
|
|
|
40
|
-
<td
|
|
40
|
+
<td
|
|
41
|
+
class={(field.hideOnMobile ? " is-hidden-touch " : "") +
|
|
42
|
+
(field.classes ? ` ${field.classes} ` : "")}
|
|
43
|
+
{title}
|
|
44
|
+
>
|
|
41
45
|
{#if field.type === "link"}
|
|
42
46
|
<UILinks values={notPath.get(field.path, item, helpers)} />
|
|
43
47
|
{:else if field.type === "button"}
|