logaretm / vee-validate

✅ Painless Vue forms
https://vee-validate.logaretm.com/v4
MIT License
10.74k stars 1.26k forks source link

Unwanted behaviour on Field type number #4482

Open Safirion opened 11 months ago

Safirion commented 11 months ago

What happened?

Hi,

Since vee-validate 4.11.6 (certainly before but after vee-validate 4.8.4) the Field type number behave weirdly.

When we type "0.001" then backspace, it remove all decimal number and we obtain "0" instead of "0.00". Same, when we type "0.1" then backspace, it remove the . and move the cursor at the begining.

https://github.com/logaretm/vee-validate/assets/11511729/49736e87-73a7-45e2-834b-a6278fb79bf8

Reproduction steps

1.Create a Field component type="number" 2.Type in it 0.001 3.Type backspace

And

1.Create a Field component type="number" 2.Type in it 0.1 3.Type backspace

Version

Vue.js 3.x and vee-validate 4.x

What browsers are you seeing the problem on?

Relevant log output

No response

Demo link

https://codesandbox.io/s/romantic-firefly-26qjcv

Code of Conduct

logaretm commented 11 months ago

The auto casting to numbers is the reason for this. I will see if I can find a workaround or introduce a way to turn it off.

Safirion commented 11 months ago

Yes, just the possibility to toggle the cast to number would be great, thank you ☺️

ghost commented 8 months ago

appears for me too. kindly resolve this

YuSyuan1208 commented 6 months ago

Maybe change baseOnInput like this?

function baseOnInput(e) {
    if(e.target.type == 'number'){
        value.value = e.target.value
        if(validateOnInput){
            validateField()
        }
    }else{
        onChangeHandler(e, validateOnInput);
    }
    if (isCallable(ctx.attrs.onInput)) {
        ctx.attrs.onInput(e);
    }
}
alaa-alsalehi commented 1 month ago

I think the root cause in this line if anyone want to dig more you can start from it. Also you should take care a simple update will break the backward compataiblity