Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set null value despite min/max values #1837

Merged
merged 3 commits into from
Nov 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions src/js/modules/infragistics.ui.editors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -4678,6 +4673,19 @@
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 (!(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;
} 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 ];
Expand Down Expand Up @@ -5326,13 +5334,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)) {
Expand Down
53 changes: 51 additions & 2 deletions tests/unit/editors/numericEditor/numericEditor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", "");
Expand Down Expand Up @@ -2813,3 +2813,52 @@ 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(12);

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");

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,
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.");
});