diff --git a/packages/devextreme/js/__internal/ui/form/m_form.ts b/packages/devextreme/js/__internal/ui/form/m_form.ts index 574e91aae1fe..64e1f0f5463e 100644 --- a/packages/devextreme/js/__internal/ui/form/m_form.ts +++ b/packages/devextreme/js/__internal/ui/form/m_form.ts @@ -264,7 +264,7 @@ const Form = Widget.inherit({ _initMarkup() { // @ts-expect-error - ValidationEngine.addGroup(this._getValidationGroup()); + ValidationEngine.addGroup(this._getValidationGroup(), false); this._clearCachedInstances(); this._prepareFormData(); this.$element().addClass(FORM_CLASS); @@ -879,7 +879,7 @@ const Form = Widget.inherit({ const optionName = getOptionNameFromFullName(fullName); if (ITEM_OPTIONS_FOR_VALIDATION_UPDATING.includes(optionName)) { // @ts-expect-error - ValidationEngine.addGroup(this._getValidationGroup()); + ValidationEngine.addGroup(this._getValidationGroup(), false); if (this.option('showValidationSummary')) { this._validationSummary?.refreshValidationGroup(); } diff --git a/packages/devextreme/js/__internal/ui/m_validation_engine.ts b/packages/devextreme/js/__internal/ui/m_validation_engine.ts index 679ee89d2195..2e16c4df9e42 100644 --- a/packages/devextreme/js/__internal/ui/m_validation_engine.ts +++ b/packages/devextreme/js/__internal/ui/m_validation_engine.ts @@ -341,9 +341,10 @@ const rulesValidators = { }; const GroupConfig = Class.inherit({ - ctor(group) { + ctor(group, isRemovable) { this.group = group; this.validators = []; + this._isRemovable = isRemovable; this._pendingValidators = []; this._onValidatorStatusChanged = this._onValidatorStatusChanged.bind(this); this._resetValidationInfo(); @@ -559,13 +560,13 @@ const ValidationEngine = { initGroups() { this.groups = []; - this.addGroup(); + this.addGroup(undefined, false); }, - addGroup(group) { + addGroup(group, isRemovable = true) { let config = this.getGroupConfig(group); if (!config) { - config = new GroupConfig(group); + config = new GroupConfig(group, isRemovable); this.groups.push(config); } return config; @@ -782,18 +783,15 @@ const ValidationEngine = { groupConfig.registerValidator.call(groupConfig, validator); }, - _shouldRemoveGroup(group, validatorsInGroup) { - const isDefaultGroup = group === undefined; - const isValidationGroupInstance = group && group.NAME === 'dxValidationGroup'; - return !isDefaultGroup && !isValidationGroupInstance && !validatorsInGroup.length; - }, - removeRegisteredValidator(group, validator) { const config = ValidationEngine.getGroupConfig(group); if (config) { config.removeRegisteredValidator.call(config, validator); const validatorsInGroup = config.validators; - if (this._shouldRemoveGroup(group, validatorsInGroup)) { + const isRemovable = config._isRemovable; + + const shouldRemoveGroup = validatorsInGroup.length === 0 && isRemovable; + if (shouldRemoveGroup) { this.removeGroup(group); } } diff --git a/packages/devextreme/js/__internal/ui/m_validation_group.ts b/packages/devextreme/js/__internal/ui/m_validation_group.ts index 9bd94e40c99f..5f6fa9f85127 100644 --- a/packages/devextreme/js/__internal/ui/m_validation_group.ts +++ b/packages/devextreme/js/__internal/ui/m_validation_group.ts @@ -19,7 +19,7 @@ class ValidationGroup extends DOMComponent { _init() { // @ts-expect-error super._init(); - ValidationEngine.addGroup(this); + ValidationEngine.addGroup(this, false); } _initMarkup() { diff --git a/packages/devextreme/js/__internal/ui/m_validation_summary.ts b/packages/devextreme/js/__internal/ui/m_validation_summary.ts index 13c7a2284305..1a112152a53f 100644 --- a/packages/devextreme/js/__internal/ui/m_validation_summary.ts +++ b/packages/devextreme/js/__internal/ui/m_validation_summary.ts @@ -37,7 +37,7 @@ const ValidationSummary = CollectionWidget.inherit({ const $element = this.$element(); const group = this.option('validationGroup') || ValidationEngine.findGroup($element, this._modelByElement($element)); - const groupConfig = ValidationEngine.addGroup(group); + const groupConfig = ValidationEngine.addGroup(group, true); this._unsubscribeGroup(); diff --git a/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/validationGroup.tests.js b/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/validationGroup.tests.js index a214d0b74d93..b26ef3c5b0ad 100644 --- a/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/validationGroup.tests.js +++ b/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/validationGroup.tests.js @@ -307,6 +307,20 @@ QUnit.module('General', { ValidationEngine.removeRegisteredValidator(group, validator2); }); + QUnit.test('group should not be removed after its validators are removed (T1233487)', function(assert) { + const $container = $('#dxValidationGroup'); + const group = this.fixture.createGroup($container); + const adapter = sinon.createStubInstance(DefaultAdapter); + const $validator1 = $('