Skip to content

Commit

Permalink
Merge pull request IgniteUI#1810 from IgniteUI/dpetev/datepicker-IME-…
Browse files Browse the repository at this point in the history
…mode-error-18.2

IgniteUI#1695 Prevent parsing invalid date produced with IME input
  • Loading branch information
bazal4o authored Sep 26, 2018
2 parents d2478f4 + 793e13e commit ebfbed8
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/js/modules/infragistics.ui.editors.js
Original file line number Diff line number Diff line change
Expand Up @@ -5031,7 +5031,7 @@

// In case of IME input digits we need to convert
// value = $.ig.util.replaceJpToEnNumbers(value);
value = $.ig.util.IMEtoNumberString(value, $.ig.util.IMEtoENNumbersMapping);
value = $.ig.util.IMEtoNumberString(value, $.ig.util.IMEtoENNumbersMapping());

// D.P. 27th Oct 2015 Bug 208296: Don't replace group separator on actual numbers as it can be '.'
value = value.toString().replace(new RegExp($.ig.util.escapeRegExp(groupSeparator), "g"), ""); // TODO VERIFY Remove group separator cause parseInt("1,000") returns 1?
Expand Down Expand Up @@ -8396,8 +8396,8 @@
dateObj = this._getDateOffset(dateObj);
}

// TODO update all the fields
if (dateObj) {
// D.P. 26th Sep 2018 #1695 Uncaught TypeError w/ IME numbers, don't parse invalid date:
if (dateObj && dateObj.getTime() === dateObj.getTime()) {
if (this._dateIndices.yy !== undefined) {
year = this._getDateField("FullYear", dateObj).toString();
if (this._dateIndices.fourDigitYear) {
Expand Down
33 changes: 32 additions & 1 deletion tests/unit/editors/Bugs/bugs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1701,4 +1701,35 @@ QUnit.test('Bug 256852: textChanged not fired on Safari on MacOS (Grid filtering
$editor.remove();
done();
});
});
});
QUnit.test('Bug 1695 Uncaught TypeError is thrown when IME is enabled and a number is typed', function (assert) {
assert.expect(4);
var done = assert.async(),
$editor = this.util.appendToFixture(this.inputTag).igDatePicker({
regional: "ja",
dataMode:"editModeText"
}),
textChangedArgs = [];
$editor.trigger("focus");
$editor.on("igdatepickertextchanged", function (evt, args) {
textChangedArgs.push(args);
});
$editor[0].setSelectionRange(0, 0);
$.ig.TestUtil.keyDownChar(50, $editor);
$editor.trigger(jQuery.Event("compositionstart"));
$editor.trigger(jQuery.Event("compositionupdate"));
$editor.val("2" + $editor.val());
$.ig.TestUtil.keyUpChar(50, $editor);
assert.ok(true, "Text change processing did not throw.");
assert.equal(textChangedArgs.length, 1, "textChanged should be triggered");
assert.equal(textChangedArgs.pop().text, "2____/__/__", "textChanged arg should be correct");
$editor[0].setSelectionRange(1, 1);
$editor.trigger(jQuery.Event("compositionend"));
$.ig.TestUtil.wait(0) //composition handlers
.then(function () {
assert.equal($editor.val(), "2___/__/__", "IME value not converted and applied to mask.");
$editor.off("igdatepickertextchanged");
$editor.remove();
done();
});
}); // Bug 1695
22 changes: 22 additions & 0 deletions tests/unit/editors/numericEditor/numericEditor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2791,3 +2791,25 @@ QUnit.test('Numeric Editor Scrollbar maintains scroll position after animation',
done();
});
});
QUnit.test('IME input numbers', function (assert) {
assert.expect(2);
var done = assert.async(),
$editor = this.util.appendToFixture(this.inputTag).igNumericEditor();
$editor.trigger("focus");
$editor[0].setSelectionRange(0, 0);
$.ig.TestUtil.keyDownChar(50, $editor);
$editor.trigger(jQuery.Event("compositionstart"));
$editor.trigger(jQuery.Event("compositionupdate"));
$editor.val("2");
$.ig.TestUtil.keyUpChar(50, $editor);
$editor[0].setSelectionRange(1, 1);
$editor.trigger(jQuery.Event("compositionend"));
$.ig.TestUtil.wait(0) //composition handlers
.then(function () {
$editor.trigger("blur");
assert.equal($editor.val(), "2", "IME text not converted and applied to mask.");
assert.strictEqual($editor.igNumericEditor("value"), 2, "Value after IME not correct");
$editor.remove();
done();
});
}); // IME input numbers

0 comments on commit ebfbed8

Please sign in to comment.