@hmcts/ccd-case-ui-toolkit 7.4.26-exceljs-update → 7.4.26-pofcc-436-optional-text

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.
@@ -6321,15 +6321,20 @@ class FormValidatorsService {
6321
6321
  static DEFAULT_INPUT_TEXT = 'text';
6322
6322
  static DEFAULT_INPUT_TEXTAREA = 'textAreas';
6323
6323
  static addValidators(caseField, control) {
6324
- if (caseField.display_context === Constants.MANDATORY &&
6325
- !FormValidatorsService.isCustomValidatedType(caseField)) {
6326
- const validators = [Validators.required];
6324
+ const isMandatory = caseField.display_context === Constants.MANDATORY &&
6325
+ !FormValidatorsService.isCustomValidatedType(caseField);
6326
+ const isOptionalText = caseField.display_context === 'OPTIONAL' && caseField.field_type.type === 'Text';
6327
+ if (isMandatory || isOptionalText) {
6328
+ const validators = [];
6329
+ if (isMandatory) {
6330
+ validators.push(Validators.required);
6331
+ }
6327
6332
  if (caseField.field_type.type === 'Text') {
6328
6333
  validators.push(this.markDownPatternValidator());
6329
6334
  if (caseField.field_type.regular_expression) {
6330
6335
  validators.push(Validators.pattern(caseField.field_type.regular_expression));
6331
6336
  }
6332
- else {
6337
+ else if (isMandatory) {
6333
6338
  validators.push(this.emptyValidator());
6334
6339
  }
6335
6340
  if (caseField.field_type.min && (typeof caseField.field_type.min === 'number')) {
@@ -6348,7 +6353,7 @@ class FormValidatorsService {
6348
6353
  }
6349
6354
  control.setValidators(validators);
6350
6355
  }
6351
- else if (caseField.display_context === 'OPTIONAL' && (caseField.field_type.type === 'Text' || this.isTextAreaType(caseField.field_type.type))
6356
+ else if (caseField.display_context === 'OPTIONAL' && this.isTextAreaType(caseField.field_type.type)
6352
6357
  || (caseField.display_context === 'COMPLEX' && caseField.field_type.type === 'Complex')) {
6353
6358
  control.setValidators(this.markDownPatternValidator());
6354
6359
  }