Skip to content

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