Skip to content

Commit 4996c84

Browse files
Ruslan FarkhutdinovRuslan Farkhutdinov
andauthored
TextEditor Mask: Fix error on empty text paste to mask editor (T1325081) (#33038)
Co-authored-by: Ruslan Farkhutdinov <ruslan.farkhutdinov@devexpress.com>
1 parent c055bd4 commit 4996c84

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

packages/devextreme/js/__internal/ui/text_box/text_editor.mask.strategy.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,11 @@ export default class MaskStrategy {
282282

283283
this.editor._maskKeyHandler(event, () => {
284284
const pastedText = getClipboardText(event);
285+
286+
if (!pastedText) {
287+
return undefined;
288+
}
289+
285290
const restText = this.editor._maskRulesChain?.text().substring(caret?.end ?? 0);
286291
const accepted = this.editor._handleChain({
287292
text: pastedText,

packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/textEditorParts/mask.tests.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2077,6 +2077,21 @@ QUnit.module('paste', moduleConfig, () => {
20772077

20782078
assert.strictEqual(textEditor.option('text'), '16___', 'only pasted digit is added');
20792079
});
2080+
2081+
QUnit.test('paste should not throw error when paste event has no clipboard data (T1325081)', function(assert) {
2082+
const $textEditor = $('#texteditor').dxTextEditor({
2083+
mask: '+1 (000) 000-0000',
2084+
});
2085+
2086+
const $input = $textEditor.find(`.${TEXTEDITOR_INPUT_CLASS}`);
2087+
2088+
try {
2089+
$input.trigger('paste');
2090+
assert.ok(true, 'no error is thrown when paste event has no clipboard data');
2091+
} catch(e) {
2092+
assert.ok(false, `error is thrown: ${e.message}`);
2093+
}
2094+
});
20802095
});
20812096

20822097
QUnit.module('drag text', moduleConfig, () => {

0 commit comments

Comments
 (0)