From cc7317deec506844dc95e96b529bd0c9d4618aac Mon Sep 17 00:00:00 2001 From: NickMitrokhin Date: Wed, 6 May 2020 16:48:39 +0300 Subject: [PATCH 1/3] Fixes the issue --- js/ui/button.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/ui/button.js b/js/ui/button.js index 3eb968053af0..416ec913429e 100644 --- a/js/ui/button.js +++ b/js/ui/button.js @@ -133,11 +133,11 @@ class Button extends Widget { this.option('disabled', true); complete.then(({ status }) => { - needValidate = true; this.option('disabled', false); validationStatus = status; validationStatus === 'valid' && this._submitInput().click(); + needValidate = true; }); } } From 843ace6ff63283a860323218ce06f4afad05e206 Mon Sep 17 00:00:00 2001 From: NickMitrokhin Date: Wed, 6 May 2020 16:49:06 +0300 Subject: [PATCH 2/3] Adds a test --- .../DevExpress.ui.widgets/button.tests.js | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/testing/tests/DevExpress.ui.widgets/button.tests.js b/testing/tests/DevExpress.ui.widgets/button.tests.js index 6df9b7e79a9b..b36159e5ecdb 100644 --- a/testing/tests/DevExpress.ui.widgets/button.tests.js +++ b/testing/tests/DevExpress.ui.widgets/button.tests.js @@ -542,6 +542,56 @@ QUnit.module('submit behavior', { ValidationEngine.registerValidatorInGroup('testGroup', validator); this.$element.trigger('dxclick'); }); + + QUnit.test('Form should be submitted only when an async validation rule is passed positively (T887207)', function(assert) { + this.clock.restore(); + let value = 'a'; + const validValue = 'b'; + const validator = new Validator($('
').appendTo(this.$form), { + adapter: sinon.createStubInstance(DefaultAdapter), + validationRules: [{ + type: 'async', + validationCallback: function() { + const d = new Deferred(); + setTimeout(() => { + d.resolve({ + isValid: value === validValue + }); + }, 10); + return d.promise(); + } + }] + }); + const done = assert.async(); + const onSubmit = () => { + assert.strictEqual(value, validValue, 'submitted with valid value'); + + this.$form.off('submit', onSubmit); + done(); + }; + const triggerButtonClick = () => { + this.$element.trigger('dxclick'); + }; + + this.$form.on('submit', onSubmit); + + this.$element.dxButton({ + validationGroup: 'testGroup', + onOptionChanged: function(args) { + if(args.name === 'disabled') { + if(args.value === false && validator._validationInfo.result.status === 'invalid') { + setTimeout(function() { + value = validValue; + triggerButtonClick(); + }); + } + } + } + }); + + ValidationEngine.registerValidatorInGroup('testGroup', validator); + triggerButtonClick(); + }); }); QUnit.module('templates', () => { From 2d399d6b74ce6a2ffc6d82abe057a062b20ba164 Mon Sep 17 00:00:00 2001 From: NickMitrokhin Date: Wed, 6 May 2020 18:38:41 +0300 Subject: [PATCH 3/3] Test refactoring (cherry picked from commit 83da0a98c26db0a46f66c9b24e93e0edb81da1ab) --- testing/tests/DevExpress.ui.widgets/button.tests.js | 1 + 1 file changed, 1 insertion(+) diff --git a/testing/tests/DevExpress.ui.widgets/button.tests.js b/testing/tests/DevExpress.ui.widgets/button.tests.js index b36159e5ecdb..b5fd297ae46d 100644 --- a/testing/tests/DevExpress.ui.widgets/button.tests.js +++ b/testing/tests/DevExpress.ui.widgets/button.tests.js @@ -566,6 +566,7 @@ QUnit.module('submit behavior', { const onSubmit = () => { assert.strictEqual(value, validValue, 'submitted with valid value'); + ValidationEngine.initGroups(); this.$form.off('submit', onSubmit); done(); };