ArcticMediaRyan
ArcticMediaRyan

Reputation: 885

watcher not working to change to lowercase

I am trying to change the users input to lowercase. I know this looks wrong but when I try and type this.email or this.name for the watch it obviously does not work. the v-model is this.email/name accordingly.

What do I need to correct on this

data() {
            return {
                form: this.$inertia.form({
                    name: '',
                    email: '',
                    password: '',
                    password_confirmation: '',
                    birthdate: '',
                    user_latitude: '',
                    user_longitude: '',
                    user_city: '',
                    user_region: '',
                    user_country: '',
                    terms: false,
                }),
                address: "",
                user_address: [],
            }
        },
        watch: {
            email(newVal) {
                this.form.email = this.form.email.toLowerCase()
            },
            name(newVal) {
                this.form.name = this.form.name.toLowerCase()
            }
        },

Upvotes: 0

Views: 101

Answers (1)

Boussadjra Brahim
Boussadjra Brahim

Reputation: 1

You could try to watch the property path :

   watch: {
     'form.email'(newVal) {
        this.form.email = this.form.email.toLowerCase()
     },

or a filter .

Upvotes: 1

Related Questions