Skip to content

Commit

Permalink
TextBox: correct handlers order after change mask option (T1214019) (#…
Browse files Browse the repository at this point in the history
…26726)

Co-authored-by: Alexander Bulychev <git@bulychev.net>
  • Loading branch information
iBat and Alexander Bulychev authored Feb 21, 2024
1 parent 655fbe2 commit ea65741
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/devextreme/js/ui/text_box/ui.text_editor.mask.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ const TextEditorMask = TextEditorBase.inherit({
this._updateHiddenElement();
this._renderMask();
this._validateMask();
this._refreshValueChangeEvent();
},

_processEmptyMask: function(mask) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ export default class MaskStrategy {
clearTimeout(this._dragTimer);
}

_clearTimers() {
this._clearDragTimer();
clearTimeout(this._caretTimeout);
clearTimeout(this._inputHandlerTimer);
}

getHandler(handlerName) {
return (args) => {
Expand All @@ -275,12 +280,11 @@ export default class MaskStrategy {
}

detachEvents() {
this._clearTimers();
EventsEngine.off(this._editorInput(), `.${MASK_EVENT_NAMESPACE}`);
}

clean() {
this._clearDragTimer();
clearTimeout(this._caretTimeout);
clearTimeout(this._inputHandlerTimer);
this._clearTimers();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2625,6 +2625,36 @@ QUnit.module('Hidden input', {}, () => {
assert.equal($hiddenInput.attr('name'), 'Editor with mask', 'name of hidden input');
});

QUnit.test('Value change should work as usual after mask option is updated programmatically (T1214019)', function(assert) {
const $textEditor = $('#texteditor').dxTextEditor({
valueChangeEvent: 'input',
mask: '000',
});
const $input = $textEditor.find(`.${TEXTEDITOR_INPUT_CLASS}`);
const instance = $textEditor.dxTextEditor('instance');

keyboardMock($input, true)
.caret(0)
.type('1')
.change();

$textEditor.blur();
instance.option('mask', '0000');
keyboardMock($input, true)
.caret(1)
.type('2')
.change();

$textEditor.blur();
instance.option('mask', '000');

const $hiddenInput = $textEditor.find('input[type=hidden]');

assert.strictEqual($input.val(), '12_', 'Value is saved');
assert.strictEqual($hiddenInput.val(), '12', 'Hidden value is saved');
assert.strictEqual(instance.option('value'), '12', 'Value option is correct');
});

[
{ useMaskedValue: true, value: '12-34-' },
{ useMaskedValue: false, value: '1234' }
Expand Down

0 comments on commit ea65741

Please sign in to comment.