cleave.js icon indicating copy to clipboard operation
cleave.js copied to clipboard

Fix duplicate numbers are entered when input number with microsoft pinyin

Open kingller opened this issue 4 years ago • 3 comments

https://github.com/nosir/cleave.js/issues/656

kingller avatar Jun 28 '21 08:06 kingller

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]);
};

sleest avatar Jul 06 '21 04:07 sleest

OK. Thanks.

kingller avatar Jul 06 '21 05:07 kingller