1

Actually my problem I am checking when a particular value is valid through v-on:input. If, the value is invalid I get the response as "invalid data" and i display the same. But, when the value becomes valid, the "invalid data" is not hiding. How to I able to do so.

My code is

  methods: {
            checkLimit: function () {
                var vm = this;
                data = {};
                if (this.no != '') data['no'] = this.no;
                $.ajax({
                    url: "doc/checkNumber",
                    method: "POST",
                    data: data,
                    dataType: "JSON",
                    success: function (e) {
                          if (e.status == true) {
                                       }
                           else{
                            console.log(e.msg);
                            vm.error = e.msg;
                            }

                    },
                });
            },
} 

So if status is false, I am showing as

<input type="text" class="form-control" v-model="orno" required="" 
v-on:input="checkLimit" maxlength="3"><p>{{error}}</p>

But when Status is true the error message is still present. How can I update based on the change?

2 Answers 2

2

You should set the error to '' when the e.status is true. Like this

 success: function (e) {
    if (e.status == true) {
        vm.error = '';
    } else {
       console.log(e.msg);
        vm.error = e.msg;
    }
 },
Sign up to request clarification or add additional context in comments.

Comments

1

Simple: in checkLimit do vm.error=null on success. Then in the template do <p v-if="error">{{error}}</p>.

Since in vue all data is reactive p will disappear when error is falsy.

EDIT: if you want to keep the p and toggle the message do as suggested in the other comment (no v-if).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.