From 52a364582ecdd957b4e15b192db0e0c16e73446e Mon Sep 17 00:00:00 2001 From: NikolayAlipiev Date: Thu, 8 Nov 2018 13:40:48 +0200 Subject: [PATCH 1/3] test(igNumeriEditor): Set null value despite min/max values #1834 --- .../numericEditor/numericEditor-test.js | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/tests/unit/editors/numericEditor/numericEditor-test.js b/tests/unit/editors/numericEditor/numericEditor-test.js index 9cbc1425b..5a5b83345 100644 --- a/tests/unit/editors/numericEditor/numericEditor-test.js +++ b/tests/unit/editors/numericEditor/numericEditor-test.js @@ -2565,12 +2565,12 @@ QUnit.test("Test allowNullValue and NullValue at initialization #779", function maxValue: -3, allowNullValue: true }); - assert.equal($editor.igNumericEditor("value"), -3, "Null value should be ignored on init and default to max."); + assert.equal($editor.igNumericEditor("value"), 5, "Null value should be set on init and default max should be ignored."); $editor.igNumericEditor("value", -5); $editor.igNumericEditor("clearButton").trigger("click"); - assert.equal($editor.igNumericEditor("value"), -3, "Null value should be ignored on clear and default to max."); + assert.equal($editor.igNumericEditor("value"), 5, "Null value should be set on clear."); //verify empty string is still accepted $editor.igNumericEditor("value", ""); @@ -2813,3 +2813,39 @@ QUnit.test('IME input numbers', function (assert) { done(); }); }); // IME input numbers + +QUnit.test('Numeric Editor Allow null value should take precedence over min/max values', function (assert) { + assert.expect(10); + + var $editor = this.util.appendToFixture(this.inputTag).igNumericEditor({ + dataMode: "int", + allowNullValue : true, + maxValue: 100, + minValue: 5, + value: null, + width: 190 + }); + assert.equal($editor.igNumericEditor("value"), null, "The value is not correct."); + assert.equal($editor.igNumericEditor("displayValue"), "", "The displayed value is not correct."); + + $editor.igNumericEditor("value", 3); + assert.equal($editor.igNumericEditor("value"), 5, "The value is not correct."); + assert.equal($editor.igNumericEditor("displayValue"), "5", "The displayed value is not correct."); + + $editor.igNumericEditor("value", null); + assert.equal($editor.igNumericEditor("value"), null, "The value is not correct."); + assert.equal($editor.igNumericEditor("displayValue"), "", "The displayed value is not correct."); + + $editor.igNumericEditor("value", 3); + assert.equal($editor.igNumericEditor("value"), 5, "The value is not correct."); + assert.equal($editor.igNumericEditor("displayValue"), "5", "The displayed value is not correct."); + $editor.igNumericEditor("destroy"); + + $editor = this.util.appendToFixture(this.inputTag).igNumericEditor({ + allowNullValue: true, + maxValue: 24, + minValue: 0.25 + }); + assert.equal($editor.igNumericEditor("value"), null, "The value is not correct."); + assert.equal($editor.igNumericEditor("displayValue"), "", "The displayed value is not correct."); +}); From 91c85628a11dcbf9f661541b764bc75a6e6bd4b1 Mon Sep 17 00:00:00 2001 From: NikolayAlipiev Date: Thu, 8 Nov 2018 15:00:19 +0200 Subject: [PATCH 2/3] fix(igNumeriEditor): Set null value despite min/max values #1834 --- src/js/modules/infragistics.ui.editors.js | 27 ++++++++++++----------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/js/modules/infragistics.ui.editors.js b/src/js/modules/infragistics.ui.editors.js index b1fe07462..f0d045af2 100644 --- a/src/js/modules/infragistics.ui.editors.js +++ b/src/js/modules/infragistics.ui.editors.js @@ -4574,12 +4574,7 @@ return this.options[ name ] !== null ? this.options[ name ] : this._getRegionalValue(regName); }, _setInitialValue: function (value) { // NumericEditor - // D.P. 6th Mar 2017 #777 'minValue/maxValue options are not respected at initialization' - if (!isNaN(this.options.minValue) && this.options.minValue > value) { - value = this.options.minValue; - } else if (!isNaN(this.options.maxValue) && this.options.maxValue < value) { - value = this.options.maxValue; - } + value = this._getValueBetweenMinMax(value); this._super(value); }, _applyOptions: function () { // NumericEditor @@ -4678,6 +4673,18 @@ this.options.maxDecimals = this._getOptionOrRegionalValue("minDecimals"); } }, + _getValueBetweenMinMax: function(value) { + // N.A. 7 November 2018, Bug #1834, Initial value that is null, should not be overwritten by the min/max values. + if (value !== this.options.nullValue) { + // D.P. 6th Mar 2017 #777 'minValue/maxValue options are not respected at initialization' + if (!isNaN(this.options.minValue) && this.options.minValue > value) { + value = this.options.minValue; + } else if (!isNaN(this.options.maxValue) && this.options.maxValue < value) { + value = this.options.maxValue; + } + } + return value; + }, _setOption: function (option, value) { // igNumericEditor /* igNumericEditor custom setOption goes here */ var prevValue = this.options[ option ]; @@ -5326,13 +5333,7 @@ newValue = this.options.nullValue; } - // D.P. nullValue does not override min/max - // If the min value is different from zero, we clear the value with the minimum value. - if (!isNaN(this.options.minValue) && this.options.minValue > newValue) { - newValue = this.options.minValue; - } else if (!isNaN(this.options.maxValue) && this.options.maxValue < newValue) { - newValue = this.options.maxValue; - } + newValue = this._getValueBetweenMinMax(newValue); //D.P. This handles both invalid nullValue and 0 not being in the list of items for #942 if (!this._validateValue(newValue)) { From 12e3bf158007b2a6290de4cc92c6d3f340ebf4fe Mon Sep 17 00:00:00 2001 From: NikolayAlipiev Date: Thu, 8 Nov 2018 17:16:30 +0200 Subject: [PATCH 3/3] fix(igNumericEditor): check allowNullValue = false #1834 --- src/js/modules/infragistics.ui.editors.js | 3 ++- .../editors/numericEditor/numericEditor-test.js | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/js/modules/infragistics.ui.editors.js b/src/js/modules/infragistics.ui.editors.js index f0d045af2..7e7c74747 100644 --- a/src/js/modules/infragistics.ui.editors.js +++ b/src/js/modules/infragistics.ui.editors.js @@ -4674,8 +4674,9 @@ } }, _getValueBetweenMinMax: function(value) { + // N.A. 7 November 2018, Bug #1834, Initial value that is null, should not be overwritten by the min/max values. - if (value !== this.options.nullValue) { + if (!(this.options.allowNullValue && value === this.options.nullValue)) { // D.P. 6th Mar 2017 #777 'minValue/maxValue options are not respected at initialization' if (!isNaN(this.options.minValue) && this.options.minValue > value) { value = this.options.minValue; diff --git a/tests/unit/editors/numericEditor/numericEditor-test.js b/tests/unit/editors/numericEditor/numericEditor-test.js index 5a5b83345..a7c183778 100644 --- a/tests/unit/editors/numericEditor/numericEditor-test.js +++ b/tests/unit/editors/numericEditor/numericEditor-test.js @@ -2815,7 +2815,7 @@ QUnit.test('IME input numbers', function (assert) { }); // IME input numbers QUnit.test('Numeric Editor Allow null value should take precedence over min/max values', function (assert) { - assert.expect(10); + assert.expect(12); var $editor = this.util.appendToFixture(this.inputTag).igNumericEditor({ dataMode: "int", @@ -2841,6 +2841,19 @@ QUnit.test('Numeric Editor Allow null value should take precedence over min/max assert.equal($editor.igNumericEditor("displayValue"), "5", "The displayed value is not correct."); $editor.igNumericEditor("destroy"); + var $editor = this.util.appendToFixture(this.inputTag).igNumericEditor({ + dataMode: "int", + allowNullValue : false, + maxValue: 100, + minValue: 5, + value: null, + width: 190 + }); + + assert.equal($editor.igNumericEditor("value"), 5, "The value is not correct."); + assert.equal($editor.igNumericEditor("displayValue"), "5", "The displayed value is not correct."); + $editor.igNumericEditor("destroy"); + $editor = this.util.appendToFixture(this.inputTag).igNumericEditor({ allowNullValue: true, maxValue: 24,