@processmaker/screen-builder 3.8.39 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@processmaker/screen-builder",
3
- "version": "3.8.39",
3
+ "version": "3.8.40",
4
4
  "scripts": {
5
5
  "dev": "VITE_COVERAGE=true vite",
6
6
  "build": "vite build",
@@ -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
- async addValidations(validations) {
243
- // Disable validations if field is hidden
244
- if (!this.isVisible()) {
245
- return;
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
- if (this.element.config && this.element.config.readonly) {
248
- //readonly elements do not need validation
249
- return;
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
- if (this.element.config && this.element.config.disabled) {
252
- //disabled elements do not need validation
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 (!(this.element.config && this.element.config.name && typeof this.element.config.name === 'string' && this.element.config.name.match(/^[a-zA-Z_][0-9a-zA-Z_.]*$/))) {
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 conditionalHide = this.element.config.conditionalHide;
262
- const parentVisibilityRule = this.parentVisibilityRule;
263
- const insideLoop = this.insideLoop || false;
264
- const deviceConfig = this.element.config.deviceVisibility
265
- ? this.element.config.deviceVisibility
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] = function(...props) {
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
- let validationFn = validators[validationConfig];
309
+ const validationFn = validators[validationConfig];
339
310
  if (!validationFn) {
340
- // eslint-disable-next-line no-console
341
311
  return;
342
312
  }
343
- fieldValidation[validationConfig] = function(...props) {
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
  }