@alfresco/adf-core 8.4.0-19864816317 → 8.4.0-19889178778

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.
@@ -20754,6 +20754,7 @@ class FormFieldModel extends FormWidgetModel {
20754
20754
  this.params = {};
20755
20755
  this.isVisible = true;
20756
20756
  this.visibilityCondition = null;
20757
+ this.checkParentVisibilityForValidation = false;
20757
20758
  this.enableFractions = false;
20758
20759
  this.currency = null;
20759
20760
  this.dateDisplayFormat = this.defaultDateFormat;
@@ -20796,6 +20797,7 @@ class FormFieldModel extends FormWidgetModel {
20796
20797
  this.hyperlinkUrl = json.hyperlinkUrl;
20797
20798
  this.displayText = json.displayText;
20798
20799
  this.visibilityCondition = formFieldVisibilityConditionHandler.getVisibilityCondition(this.id, json.visibilityCondition, parent);
20800
+ this.checkParentVisibilityForValidation = json.checkParentVisibilityForValidation ?? false;
20799
20801
  this.enableFractions = json.enableFractions;
20800
20802
  this.currency = json.currency;
20801
20803
  this.dateDisplayFormat = json.dateDisplayFormat || this.getDefaultDateFormat(json);
@@ -21395,7 +21397,7 @@ class RequiredFieldValidator {
21395
21397
  return field && this.supportedTypes.indexOf(field.type) > -1 && field.required;
21396
21398
  }
21397
21399
  validate(field) {
21398
- if (this.isSupported(field) && field.isVisible) {
21400
+ if (this.isSupported(field) && field.form && !field.form.isFieldOrParentHidden(field)) {
21399
21401
  if (field.type === FormFieldTypes.RADIO_BUTTONS) {
21400
21402
  const option = field.options.find((opt) => opt.id === field.value);
21401
21403
  return !!option;
@@ -21427,7 +21429,7 @@ class NumberFieldValidator {
21427
21429
  return field && this.supportedTypes.indexOf(field.type) > -1;
21428
21430
  }
21429
21431
  validate(field) {
21430
- if (this.isSupported(field) && field.isVisible) {
21432
+ if (this.isSupported(field) && field.form && !field.form.isFieldOrParentHidden(field)) {
21431
21433
  if (field.value === null || field.value === undefined || field.value === '') {
21432
21434
  return true;
21433
21435
  }
@@ -21453,7 +21455,7 @@ class MinLengthFieldValidator {
21453
21455
  return field && this.supportedTypes.indexOf(field.type) > -1 && field.minLength > 0;
21454
21456
  }
21455
21457
  validate(field) {
21456
- if (this.isSupported(field) && field.value && field.isVisible) {
21458
+ if (this.isSupported(field) && field.value && field.form && !field.form.isFieldOrParentHidden(field)) {
21457
21459
  if (field.value.length >= field.minLength) {
21458
21460
  return true;
21459
21461
  }
@@ -21473,7 +21475,7 @@ class MaxLengthFieldValidator {
21473
21475
  return field && this.supportedTypes.indexOf(field.type) > -1 && this.getMaxLength(field) > 0;
21474
21476
  }
21475
21477
  validate(field) {
21476
- if (this.isSupported(field) && field.value && field.isVisible) {
21478
+ if (this.isSupported(field) && field.value && field.form && !field.form.isFieldOrParentHidden(field)) {
21477
21479
  if (field.value.toString().length <= this.getMaxLength(field)) {
21478
21480
  return true;
21479
21481
  }
@@ -21495,7 +21497,7 @@ class MinValueFieldValidator {
21495
21497
  return field && this.supportedTypes.indexOf(field.type) > -1 && NumberFieldValidator.isNumber(field.minValue);
21496
21498
  }
21497
21499
  validate(field) {
21498
- if (this.isSupported(field) && field.value && field.isVisible) {
21500
+ if (this.isSupported(field) && field.value && field.form && !field.form.isFieldOrParentHidden(field)) {
21499
21501
  const value = +field.value;
21500
21502
  const minValue = +field.minValue;
21501
21503
  if (value >= minValue) {
@@ -21516,7 +21518,7 @@ class MaxValueFieldValidator {
21516
21518
  return field && this.supportedTypes.indexOf(field.type) > -1 && NumberFieldValidator.isNumber(field.maxValue);
21517
21519
  }
21518
21520
  validate(field) {
21519
- if (this.isSupported(field) && field.value && field.isVisible) {
21521
+ if (this.isSupported(field) && field.value && field.form && !field.form.isFieldOrParentHidden(field)) {
21520
21522
  const value = +field.value;
21521
21523
  const maxValue = +field.maxValue;
21522
21524
  if (value <= maxValue) {
@@ -21537,7 +21539,7 @@ class RegExFieldValidator {
21537
21539
  return field && this.supportedTypes.indexOf(field.type) > -1 && !!field.regexPattern;
21538
21540
  }
21539
21541
  validate(field) {
21540
- if (this.isSupported(field) && field.value && field.isVisible) {
21542
+ if (this.isSupported(field) && field.value && field.form && !field.form.isFieldOrParentHidden(field)) {
21541
21543
  if (field.value.length > 0 && field.value.match(new RegExp('^' + field.regexPattern + '$'))) {
21542
21544
  return true;
21543
21545
  }
@@ -21570,7 +21572,7 @@ class FixedValueFieldValidator {
21570
21572
  return field.options && field.options.length > 0;
21571
21573
  }
21572
21574
  validate(field) {
21573
- if (this.isSupported(field) && field.isVisible) {
21575
+ if (this.isSupported(field) && field.form && !field.form.isFieldOrParentHidden(field)) {
21574
21576
  if (this.hasStringValue(field) && this.hasOptions(field) && !this.hasValidNameOrValidId(field)) {
21575
21577
  field.validationSummary.message = 'FORM.FIELD.VALIDATOR.INVALID_VALUE';
21576
21578
  return false;
@@ -21587,7 +21589,7 @@ class DecimalFieldValidator {
21587
21589
  return field && this.supportedTypes.indexOf(field.type) > -1 && !!field.value;
21588
21590
  }
21589
21591
  validate(field) {
21590
- const shouldValidateField = this.isSupported(field) && field.isVisible;
21592
+ const shouldValidateField = this.isSupported(field) && field.form && !field.form.isFieldOrParentHidden(field);
21591
21593
  if (!shouldValidateField) {
21592
21594
  return true;
21593
21595
  }
@@ -21659,6 +21661,7 @@ class FormModel {
21659
21661
  this.isValid = true;
21660
21662
  this.processVariables = [];
21661
21663
  this.variables = [];
21664
+ this.enableParentVisibilityCheck = false;
21662
21665
  this.readOnly = readOnly;
21663
21666
  this.json = json;
21664
21667
  if (json) {
@@ -22016,6 +22019,103 @@ class FormModel {
22016
22019
  loadInjectedFieldValidators(injectedFieldValidators) {
22017
22020
  this.fieldValidators = injectedFieldValidators ? [...FORM_FIELD_VALIDATORS, ...injectedFieldValidators] : [...FORM_FIELD_VALIDATORS];
22018
22021
  }
22022
+ /**
22023
+ * Checks if a field or any of its parent containers/groups/sections is hidden.
22024
+ * Returns true if the field should skip validation (field or parent is hidden).
22025
+ *
22026
+ * Parent visibility is only checked if:
22027
+ * - `enableParentVisibilityCheck` is true
22028
+ * - `field.checkParentVisibilityForValidation` is true (field opt-in enabled)
22029
+ *
22030
+ * @param field The form field to check
22031
+ * @returns true if field or parent is hidden, false otherwise
22032
+ */
22033
+ isFieldOrParentHidden(field) {
22034
+ if (!field) {
22035
+ return false;
22036
+ }
22037
+ if (!field.isVisible) {
22038
+ return true;
22039
+ }
22040
+ if (this.enableParentVisibilityCheck && field.checkParentVisibilityForValidation) {
22041
+ return this.hasHiddenParent(field);
22042
+ }
22043
+ return false;
22044
+ }
22045
+ /**
22046
+ * Checks if the given field has a hidden parent container/group/section.
22047
+ *
22048
+ * @param targetField The form field to check
22049
+ * @returns true if field has a hidden parent, false otherwise
22050
+ */
22051
+ hasHiddenParent(targetField) {
22052
+ if (!targetField || !this.fields || this.fields.length === 0) {
22053
+ return false;
22054
+ }
22055
+ for (const rootElement of this.fields) {
22056
+ const parent = this.findParentInElement(rootElement, targetField);
22057
+ if (parent && !parent.isVisible) {
22058
+ return true;
22059
+ }
22060
+ }
22061
+ return false;
22062
+ }
22063
+ /**
22064
+ * Recursively searches for a field within an element (container/group/section).
22065
+ * Returns the parent element if field is found within it, null otherwise.
22066
+ *
22067
+ * @param element The container/group/section to search in
22068
+ * @param targetField The form field to find
22069
+ * @returns Parent element if field found, null otherwise
22070
+ */
22071
+ findParentInElement(element, targetField) {
22072
+ if (!element || !targetField) {
22073
+ return null;
22074
+ }
22075
+ const columns = this.getColumnsFromElement(element);
22076
+ if (!columns || columns.length === 0) {
22077
+ return null;
22078
+ }
22079
+ return this.searchFieldsInColumns(columns, element, targetField);
22080
+ }
22081
+ getColumnsFromElement(element) {
22082
+ if (element instanceof ContainerModel) {
22083
+ return element.field?.columns || null;
22084
+ }
22085
+ else if (element instanceof FormFieldModel && element.type === FormFieldTypes.SECTION) {
22086
+ return element.columns || null;
22087
+ }
22088
+ return null;
22089
+ }
22090
+ searchFieldsInColumns(columns, parentElement, targetField) {
22091
+ for (const column of columns) {
22092
+ if (!column?.fields || column.fields.length === 0) {
22093
+ continue;
22094
+ }
22095
+ const result = this.searchFieldsInColumn(column.fields, parentElement, targetField);
22096
+ if (result) {
22097
+ return result;
22098
+ }
22099
+ }
22100
+ return null;
22101
+ }
22102
+ searchFieldsInColumn(fields, parentElement, targetField) {
22103
+ for (const field of fields) {
22104
+ if (!field) {
22105
+ continue;
22106
+ }
22107
+ if (field.id === targetField.id) {
22108
+ return parentElement;
22109
+ }
22110
+ if (field.type === FormFieldTypes.SECTION) {
22111
+ const nestedParent = this.findParentInElement(field, targetField);
22112
+ if (nestedParent) {
22113
+ return !parentElement.isVisible ? parentElement : nestedParent;
22114
+ }
22115
+ }
22116
+ }
22117
+ return null;
22118
+ }
22019
22119
  }
22020
22120
 
22021
22121
  /*!