@processmaker/screen-builder 3.8.38 → 3.8.40
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/dist/vue-form-builder.es.js +5313 -5311
- package/dist/vue-form-builder.es.js.map +1 -1
- package/dist/vue-form-builder.umd.js +51 -51
- package/dist/vue-form-builder.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/ValidationsFactory.js +94 -105
- package/src/mixins/ValidationRules.js +13 -3
package/package.json
CHANGED
|
@@ -157,7 +157,7 @@ class FormLoopValidations extends Validations {
|
|
|
157
157
|
return;
|
|
158
158
|
}
|
|
159
159
|
page.items.filter(item => {
|
|
160
|
-
if (item.component === 'FormLoop' && item.config.name === this.element.config.name) {
|
|
160
|
+
if (item.component === 'FormLoop' && item.config.name === this.element.config.name && item !== this.element) {
|
|
161
161
|
siblings.push(item);
|
|
162
162
|
}
|
|
163
163
|
});
|
|
@@ -239,31 +239,52 @@ class PageNavigateValidations extends Validations {
|
|
|
239
239
|
* Add validations for a form element
|
|
240
240
|
*/
|
|
241
241
|
class FormElementValidations extends Validations {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
242
|
+
/**
|
|
243
|
+
* Returns true when this field should be skipped entirely (not validated).
|
|
244
|
+
* Inside loops, conditionalHide is per-row and handled by the runtime closure,
|
|
245
|
+
* so only the device-level visibleInDevice flag is checked statically.
|
|
246
|
+
*/
|
|
247
|
+
shouldSkipValidation() {
|
|
248
|
+
if (this.insideLoop) {
|
|
249
|
+
const visibleInDevice =
|
|
250
|
+
this.element.visibleInDevice === null || this.element.visibleInDevice === undefined
|
|
251
|
+
? true
|
|
252
|
+
: this.element.visibleInDevice;
|
|
253
|
+
return !visibleInDevice;
|
|
246
254
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
255
|
+
return !this.isVisible();
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Returns true when the element has a usable config with a valid variable name
|
|
260
|
+
* and is neither readonly nor disabled.
|
|
261
|
+
*/
|
|
262
|
+
isValidElement() {
|
|
263
|
+
const { config } = this.element;
|
|
264
|
+
if (!config || config.readonly || config.disabled) {
|
|
265
|
+
return false;
|
|
250
266
|
}
|
|
251
|
-
|
|
252
|
-
|
|
267
|
+
return config.name &&
|
|
268
|
+
typeof config.name === 'string' &&
|
|
269
|
+
config.name.match(/^[a-zA-Z_][0-9a-zA-Z_.]*$/);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
async addValidations(validations) {
|
|
273
|
+
if (this.shouldSkipValidation()) {
|
|
253
274
|
return;
|
|
254
275
|
}
|
|
255
|
-
if (!
|
|
256
|
-
//element invalid
|
|
276
|
+
if (!this.isValidElement()) {
|
|
257
277
|
return;
|
|
258
278
|
}
|
|
259
279
|
const fieldName = this.element.config.name;
|
|
260
280
|
const validationConfig = this.element.config.validation;
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
: { showForDesktop: true, showForMobile: true }
|
|
281
|
+
const closureOptions = {
|
|
282
|
+
fieldName,
|
|
283
|
+
conditionalHide: this.element.config.conditionalHide,
|
|
284
|
+
parentVisibilityRule: this.parentVisibilityRule,
|
|
285
|
+
insideLoop: this.insideLoop || false,
|
|
286
|
+
deviceConfig: this.element.config.deviceVisibility || { showForDesktop: true, showForMobile: true },
|
|
287
|
+
};
|
|
267
288
|
|
|
268
289
|
set(validations, fieldName, get(validations, fieldName, {}));
|
|
269
290
|
const fieldValidation = get(validations, fieldName);
|
|
@@ -275,109 +296,77 @@ class FormElementValidations extends Validations {
|
|
|
275
296
|
}
|
|
276
297
|
let validationFn = validators[rule];
|
|
277
298
|
if (!validationFn) {
|
|
278
|
-
// eslint-disable-next-line no-console
|
|
279
299
|
return;
|
|
280
300
|
}
|
|
281
301
|
if (validation.configs instanceof Array) {
|
|
282
|
-
const params =
|
|
283
|
-
validation.configs.forEach((cnf) => {
|
|
284
|
-
params.push(cnf.value);
|
|
285
|
-
});
|
|
302
|
+
const params = validation.configs.map((cnf) => cnf.value);
|
|
286
303
|
params.push(fieldName);
|
|
287
304
|
validationFn = validationFn(...params);
|
|
288
305
|
}
|
|
289
|
-
fieldValidation[rule] =
|
|
290
|
-
const data = props[1];
|
|
291
|
-
const level = fieldName.split('.').length - 1;
|
|
292
|
-
const dataWithParent = this.getDataAccordingToFieldLevel(this.getRootScreen().addReferenceToParents(data), level);
|
|
293
|
-
if (parentVisibilityRule) {
|
|
294
|
-
const nextParentLevel = insideLoop ? 1 : 0;
|
|
295
|
-
const parentDataWithParent = this.getDataAccordingToFieldLevel(this.getRootScreen().addReferenceToParents(data), level + nextParentLevel);
|
|
296
|
-
let isParentVisible = true;
|
|
297
|
-
try {
|
|
298
|
-
isParentVisible = !!Parser.evaluate(parentVisibilityRule, parentDataWithParent);
|
|
299
|
-
} catch (error) {
|
|
300
|
-
isParentVisible = false;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
if (!isParentVisible ) {
|
|
304
|
-
return true;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
// Check Device Visibility
|
|
309
|
-
let visibleInDevice = true;
|
|
310
|
-
try {
|
|
311
|
-
const isMobileScreen = this.$root.$children[0].$refs.renderer.definition.isMobile;
|
|
312
|
-
visibleInDevice =
|
|
313
|
-
(isMobileScreen && deviceConfig.showForMobile) ||
|
|
314
|
-
(!isMobileScreen && deviceConfig.showForDesktop);
|
|
315
|
-
} catch (error) {
|
|
316
|
-
visibleInDevice = true;
|
|
317
|
-
}
|
|
318
|
-
if (!visibleInDevice) {
|
|
319
|
-
return true;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
// Check Field Visibility
|
|
323
|
-
let visible = true;
|
|
324
|
-
if (conditionalHide) {
|
|
325
|
-
try {
|
|
326
|
-
visible = !!Parser.evaluate(conditionalHide, dataWithParent);
|
|
327
|
-
} catch (error) {
|
|
328
|
-
visible = false;
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
if (!visible) {
|
|
332
|
-
return true;
|
|
333
|
-
}
|
|
334
|
-
return validationFn.apply(this,props);
|
|
335
|
-
};
|
|
306
|
+
fieldValidation[rule] = this.buildClosure(validationFn, closureOptions);
|
|
336
307
|
});
|
|
337
308
|
} else if (typeof validationConfig === 'string' && validationConfig) {
|
|
338
|
-
|
|
309
|
+
const validationFn = validators[validationConfig];
|
|
339
310
|
if (!validationFn) {
|
|
340
|
-
// eslint-disable-next-line no-console
|
|
341
311
|
return;
|
|
342
312
|
}
|
|
343
|
-
fieldValidation[validationConfig] =
|
|
344
|
-
const data = props[1];
|
|
345
|
-
const level = fieldName.split('.').length - 1;
|
|
346
|
-
const dataWithParent = this.getDataAccordingToFieldLevel(this.getRootScreen().addReferenceToParents(data), level);
|
|
347
|
-
// Check Parent Visibility
|
|
348
|
-
if (parentVisibilityRule) {
|
|
349
|
-
const nextParentLevel = insideLoop ? 1 : 0;
|
|
350
|
-
const parentDataWithParent = this.getDataAccordingToFieldLevel(this.getRootScreen().addReferenceToParents(data), level + nextParentLevel);
|
|
351
|
-
let isParentVisible = true;
|
|
352
|
-
try {
|
|
353
|
-
isParentVisible = !!Parser.evaluate(parentVisibilityRule, parentDataWithParent);
|
|
354
|
-
} catch (error) {
|
|
355
|
-
isParentVisible = false;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
if (!isParentVisible) {
|
|
359
|
-
return true;
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
// Check Field Visibility
|
|
363
|
-
let visible = true;
|
|
364
|
-
if (conditionalHide) {
|
|
365
|
-
try {
|
|
366
|
-
visible = !!Parser.evaluate(conditionalHide, dataWithParent);
|
|
367
|
-
} catch (error) {
|
|
368
|
-
visible = false;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
if (!visible) {
|
|
372
|
-
return true;
|
|
373
|
-
}
|
|
374
|
-
return validationFn.apply(this,props);
|
|
375
|
-
};
|
|
313
|
+
fieldValidation[validationConfig] = this.buildClosure(validationFn, closureOptions);
|
|
376
314
|
}
|
|
377
315
|
if (this.element.items) {
|
|
378
316
|
ValidationsFactory(this.element.items, { screen: this.screen, data: this.data }).addValidations(validations);
|
|
379
317
|
}
|
|
380
318
|
}
|
|
319
|
+
|
|
320
|
+
buildClosure(validationFn, { fieldName, parentVisibilityRule, insideLoop, deviceConfig, conditionalHide }) {
|
|
321
|
+
return function (...props) {
|
|
322
|
+
const data = props[1];
|
|
323
|
+
const level = fieldName.split('.').length - 1;
|
|
324
|
+
const dataWithParent = this.getDataAccordingToFieldLevel(this.getRootScreen().addReferenceToParents(data), level);
|
|
325
|
+
|
|
326
|
+
if (parentVisibilityRule) {
|
|
327
|
+
const nextParentLevel = insideLoop ? 1 : 0;
|
|
328
|
+
const parentDataWithParent = this.getDataAccordingToFieldLevel(this.getRootScreen().addReferenceToParents(data), level + nextParentLevel);
|
|
329
|
+
let isParentVisible = true;
|
|
330
|
+
try {
|
|
331
|
+
isParentVisible = !!Parser.evaluate(parentVisibilityRule, parentDataWithParent);
|
|
332
|
+
} catch (error) {
|
|
333
|
+
isParentVisible = false;
|
|
334
|
+
}
|
|
335
|
+
if (!isParentVisible) {
|
|
336
|
+
return true;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// Check Device Visibility
|
|
341
|
+
let visibleInDevice = true;
|
|
342
|
+
try {
|
|
343
|
+
const isMobileScreen = this.$root.$children[0].$refs.renderer.definition.isMobile;
|
|
344
|
+
visibleInDevice =
|
|
345
|
+
(isMobileScreen && deviceConfig.showForMobile) ||
|
|
346
|
+
(!isMobileScreen && deviceConfig.showForDesktop);
|
|
347
|
+
} catch (error) {
|
|
348
|
+
visibleInDevice = true;
|
|
349
|
+
}
|
|
350
|
+
if (!visibleInDevice) {
|
|
351
|
+
return true;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// Check Field Visibility
|
|
355
|
+
let visible = true;
|
|
356
|
+
if (conditionalHide) {
|
|
357
|
+
try {
|
|
358
|
+
visible = !!Parser.evaluate(conditionalHide, dataWithParent);
|
|
359
|
+
} catch (error) {
|
|
360
|
+
visible = false;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
if (!visible) {
|
|
364
|
+
return true;
|
|
365
|
+
}
|
|
366
|
+
return validationFn.apply(this, props);
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
|
|
381
370
|
camelCase(name) {
|
|
382
371
|
return name.replace(/_\w/g, m => m.substr(1, 1).toUpperCase());
|
|
383
372
|
}
|
|
@@ -160,8 +160,18 @@ export const regex = (expression) => helpers.withParams({expression}, (value) =>
|
|
|
160
160
|
return !!String(value).match(regexp);
|
|
161
161
|
});
|
|
162
162
|
|
|
163
|
+
const hasRequiredValue = (value) => {
|
|
164
|
+
if (value instanceof Array) {
|
|
165
|
+
return value.length > 0;
|
|
166
|
+
}
|
|
167
|
+
if (typeof value === 'string') {
|
|
168
|
+
return value.trim().length > 0;
|
|
169
|
+
}
|
|
170
|
+
return !isNil(value) && value !== false;
|
|
171
|
+
};
|
|
172
|
+
|
|
163
173
|
export const required = (value) => {
|
|
164
|
-
return
|
|
174
|
+
return hasRequiredValue(value);
|
|
165
175
|
};
|
|
166
176
|
|
|
167
177
|
export const requiredIf = (variable, expected, fieldName) => helpers.withParams({variable, expected}, function(value, data) {
|
|
@@ -174,7 +184,7 @@ export const requiredIf = (variable, expected, fieldName) => helpers.withParams(
|
|
|
174
184
|
expectedValue = expected === 'true' || expected === '1';
|
|
175
185
|
}
|
|
176
186
|
if (variableValue != expectedValue) return true;
|
|
177
|
-
return value
|
|
187
|
+
return hasRequiredValue(value);
|
|
178
188
|
});
|
|
179
189
|
|
|
180
190
|
export const requiredUnless = (variable, expected, fieldName) => helpers.withParams({variable, expected}, function(value, data) {
|
|
@@ -187,7 +197,7 @@ export const requiredUnless = (variable, expected, fieldName) => helpers.withPar
|
|
|
187
197
|
expectedValue = expected === 'true' || expected === '1';
|
|
188
198
|
}
|
|
189
199
|
if (variableValue == expectedValue) return true;
|
|
190
|
-
return value
|
|
200
|
+
return hasRequiredValue(value);
|
|
191
201
|
});
|
|
192
202
|
|
|
193
203
|
export const sameAs = (field, fieldName) => helpers.withParams({field}, function(value, data) {
|