niksmr / vue-masked-input

Masked input component for Vue.js
https://niksmr.github.io/vue-masked-input/
MIT License
454 stars 92 forks source link

Problem with mask #48

Open samik3k opened 6 years ago

samik3k commented 6 years ago

So i have

{{ phone }}
        <label for="phone">Phone</label>
        <masked-input
            id="phone"
            class="form-control string"
            v-model="phone"
            mask="\+\7 111 111-11-11"
            placeholder=""
            type="tel" />
    </div>

And i have phone: '72731241241', Every time i open this modal i will get +7 727 312-41-24 Next try +7 772 731-24-12 And next +7 777 273-12-41 And next +7 777 727-31-24...

elblasto commented 6 years ago

Same problem

a2exfr commented 5 years ago

It' look like mask work wrong, when send model data back to input. Example I have mask ="+\9\6\2 111-11-11" and enter number + 962 333-33-33. After save correct number, and then try edit, and put data back to input - result is + 962 962-33-33. It's not cut static numbers at beginning. Solution can be to save raw value@input="rawVal = arguments[1]" and use it. Or in my case, I just cut static start of mask

<masked-input  v-model="userPhone" mask="\+\9\6\2 / 11 / 111/ 1111" placeholder="Phone"/>
data() {
        return {
            phone: '',
},
computed: {
        userPhone: {
            set(val) {
                this.phone = val;
            },
            get() {
                return  this.phone.substring(4);
            },
        },
}
langald commented 5 years ago

Same problem

NetworKKnighT commented 1 month ago

It can be fixed by replacing in MaskedInput.js this line [...this.$refs.input.value].reduce((memo, item) => this.maskCore.input(item), null); with this.maskCore.paste(this.$refs.input.value);