From f7e0458de0ce5ece9dd760b822382988ab030f6c Mon Sep 17 00:00:00 2001 From: "Marco A. Nina Mena" Date: Fri, 3 Nov 2023 12:50:31 -0400 Subject: [PATCH 1/3] Add field validation show --- src/mixins/extensions/ValidationRules.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/mixins/extensions/ValidationRules.js b/src/mixins/extensions/ValidationRules.js index 44a0304c3..babf408db 100644 --- a/src/mixins/extensions/ValidationRules.js +++ b/src/mixins/extensions/ValidationRules.js @@ -17,8 +17,8 @@ export default { console.error("Invalid variable name"); } } else { - properties[':class'] = `{ 'form-group--error': showValidationErrors && ${this.checkVariableExists('$v.vdata.' + element.config.name)} && $v.vdata.${element.config.name}.$invalid || showValidationErrors && ${this.checkVariableExists('$v.schema.' + element.config.name)} && $v.schema.${element.config.name}.$invalid }`; - properties[':error'] = `showValidationErrors && ${this.checkVariableExists('$v.vdata.' + element.config.name)} && validationMessage($v.vdata.${element.config.name}) || showValidationErrors && ${this.checkVariableExists('$v.schema.' + element.config.name)} && validationMessage($v.schema.${element.config.name})`; + properties[':class'] = `{ 'form-group--error': (showValidationErrors || ${this.fieldValidationShow(element)}) && ${this.checkVariableExists('$v.vdata.' + element.config.name)} && $v.vdata.${element.config.name}.$invalid || (showValidationErrors || ${this.fieldValidationShow(element)}) && ${this.checkVariableExists('$v.schema.' + element.config.name)} && $v.schema.${element.config.name}.$invalid }`; + properties[':error'] = `(showValidationErrors || ${this.fieldValidationShow(element)}) && ${this.checkVariableExists('$v.vdata.' + element.config.name)} && validationMessage($v.vdata.${element.config.name}) || (showValidationErrors || ${this.fieldValidationShow(element)}) && ${this.checkVariableExists('$v.schema.' + element.config.name)} && validationMessage($v.schema.${element.config.name})`; } } }, @@ -53,5 +53,17 @@ export default { }, {str: '', variable: ''}); return check.str; }, + fieldValidationShow (element) { + let showError = true; + if (element.config.validation) { + const validationHidden = ['Required', 'Required if']; + element.config.validation.forEach((validation) => { + if (validationHidden.includes(validation.content)) { + showError = false; + } + }); + } + return showError; + } }, }; From 8b778073e6272f964ce48ebe830effc063b66c84 Mon Sep 17 00:00:00 2001 From: "Marco A. Nina Mena" Date: Fri, 3 Nov 2023 16:01:21 -0400 Subject: [PATCH 2/3] Add validation string --- src/mixins/extensions/ValidationRules.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/mixins/extensions/ValidationRules.js b/src/mixins/extensions/ValidationRules.js index babf408db..9fccaa9c1 100644 --- a/src/mixins/extensions/ValidationRules.js +++ b/src/mixins/extensions/ValidationRules.js @@ -54,14 +54,19 @@ export default { return check.str; }, fieldValidationShow (element) { + console.log('fieldValidationShow', element.config.name, element.config, element.config.validation); let showError = true; - if (element.config.validation) { + if (element.config && element.config.validation) { const validationHidden = ['Required', 'Required if']; - element.config.validation.forEach((validation) => { - if (validationHidden.includes(validation.content)) { - showError = false; - } - }); + if (Array.isArray(element.config.validation)) { + element.config.validation.forEach((validation) => { + if (validationHidden.includes(validation.content)) { + showError = false; + } + }); + } else { + showError = validationHidden.includes(element.config.validation); + } } return showError; } From a9dd93ef128b603f6c0eea4122351f9a00b0cf9e Mon Sep 17 00:00:00 2001 From: "Marco A. Nina Mena" Date: Fri, 3 Nov 2023 17:07:37 -0400 Subject: [PATCH 3/3] Add validation in test showOnSubmit --- src/mixins/extensions/ValidationRules.js | 1 - tests/e2e/specs/ValidationShownOnSubmit.spec.js | 17 +++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/mixins/extensions/ValidationRules.js b/src/mixins/extensions/ValidationRules.js index 9fccaa9c1..553cabd84 100644 --- a/src/mixins/extensions/ValidationRules.js +++ b/src/mixins/extensions/ValidationRules.js @@ -54,7 +54,6 @@ export default { return check.str; }, fieldValidationShow (element) { - console.log('fieldValidationShow', element.config.name, element.config, element.config.validation); let showError = true; if (element.config && element.config.validation) { const validationHidden = ['Required', 'Required if']; diff --git a/tests/e2e/specs/ValidationShownOnSubmit.spec.js b/tests/e2e/specs/ValidationShownOnSubmit.spec.js index 812206d67..584f06dd2 100644 --- a/tests/e2e/specs/ValidationShownOnSubmit.spec.js +++ b/tests/e2e/specs/ValidationShownOnSubmit.spec.js @@ -9,8 +9,14 @@ describe('Validation Rules', () => { it('Invalid default values', () => { cy.loadFromJson('validation_rules.json', 0); cy.get('[data-cy=mode-preview]').click(); - - cy.shouldNotHaveValidationErrors('screen-field-form_input_1'); + + cy.shouldHaveValidationErrors('screen-field-form_checkbox_1'); + cy.shouldHaveValidationErrors('screen-field-form_input_1'); + cy.shouldHaveValidationErrors('screen-field-form_input_2'); + cy.shouldNotHaveValidationErrors('screen-field-form_input_3'); + cy.shouldHaveValidationErrors('screen-field-form_input_4'); + cy.shouldNotHaveValidationErrors('screen-field-form_input_5'); + cy.shouldNotHaveValidationErrors('screen-field-form_input_6'); cy.get('[data-cy=preview-content] .page button').click(); @@ -19,6 +25,13 @@ describe('Validation Rules', () => { cy.get('[data-cy=preview-content] [data-cy="screen-field-form_input_1"]') .clear() .type('on'); + + cy.shouldHaveValidationErrors('screen-field-form_checkbox_1'); cy.shouldNotHaveValidationErrors('screen-field-form_input_1'); + cy.shouldHaveValidationErrors('screen-field-form_input_2'); + cy.shouldNotHaveValidationErrors('screen-field-form_input_3'); + cy.shouldHaveValidationErrors('screen-field-form_input_4'); + cy.shouldNotHaveValidationErrors('screen-field-form_input_5'); + cy.shouldNotHaveValidationErrors('screen-field-form_input_6'); }); });