Skip to content

Fix duplicate numbers are entered when input number with microsoft pinyin - #663

Open
kingller wants to merge 1 commit into
nosir:masterfrom
kingller:fix-microsoft-pinyin
Open

Fix duplicate numbers are entered when input number with microsoft pinyin#663
kingller wants to merge 1 commit into
nosir:masterfrom
kingller:fix-microsoft-pinyin

Conversation

@kingller

Copy link
Copy Markdown

@sleest

sleest commented Jul 6, 2021

Copy link
Copy Markdown

thanks to @kingller 's committed : #663
the issue seem related to windows IME which confused me a lot
for guys using cleave.js via javascript, a simple patching way until fixed release maybe

var oldCleaveInit = Cleave.prototype.init;
var oldCleaveOnChange = Cleave.prototype.onChange;
Cleave.prototype.init = function() {
    var owner = this;
    oldCleaveInit.apply(this);
    owner.element.addEventListener('compositionstart', function() {
        owner.isComposition = true;
    });
    owner.element.addEventListener('compositionend', function(event) {
        owner.isComposition = false;
        owner.onChange(event);
    });
};
Cleave.prototype.onChange = function(event) {
    var owner = this;
    if (this.isComposition) {
        owner.properties.result = event.target.value;
        owner.updateValueState();
        return;
    }
    oldCleaveOnChange.apply(this, [event]);
};

@kingller

kingller commented Jul 6, 2021

Copy link
Copy Markdown
Author

OK. Thanks.

@kangfizz

Copy link
Copy Markdown

thanks to @kingller 's committed : #663 the issue seem related to windows IME which confused me a lot for guys using cleave.js via javascript, a simple patching way until fixed release maybe

var oldCleaveInit = Cleave.prototype.init;
var oldCleaveOnChange = Cleave.prototype.onChange;
Cleave.prototype.init = function() {
    var owner = this;
    oldCleaveInit.apply(this);
    owner.element.addEventListener('compositionstart', function() {
        owner.isComposition = true;
    });
    owner.element.addEventListener('compositionend', function(event) {
        owner.isComposition = false;
        owner.onChange(event);
    });
};
Cleave.prototype.onChange = function(event) {
    var owner = this;
    if (this.isComposition) {
        owner.properties.result = event.target.value;
        owner.updateValueState();
        return;
    }
    oldCleaveOnChange.apply(this, [event]);
};

I modify onChange event with below code and work well, maybe this help someone.
(as using zh-TW input method and numeric keypad)

Cleave.prototype.onChange = function(event) {
  const owner = this
  if (owner.isComposition && event.inputType === 'insertCompositionText') return
  oldCleaveOnChange.apply(this, [event])
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants