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

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kingller
Copy link

@sleest
Copy link

sleest commented Jul 6, 2021

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
Copy link
Author

kingller commented Jul 6, 2021

OK. Thanks.

@kangfizz
Copy link

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