Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v-model with attribute lazy #2083

Closed
PavelCSS opened this issue Dec 25, 2015 · 5 comments
Closed

v-model with attribute lazy #2083

PavelCSS opened this issue Dec 25, 2015 · 5 comments

Comments

@PavelCSS
Copy link

v-model with attribute lazy is activated twice when blur and change. I think enough to a change event?!

@ludo237
Copy link

ludo237 commented Dec 25, 2015

Could you provide an example please?

@PavelCSS
Copy link
Author

when you first add the date watcher activated twice
http://codepen.io/PavelCSS/pen/obzeOz?editors=101

@ludo237
Copy link

ludo237 commented Dec 25, 2015

I don't think that I've understand yourissue very well. To be honest it seems to me that the watch callback lacks in logic.

Your original pen shows that as soon as the input got focus the alert get a +1. But that's because the watch is missing some logic.

Try this, a simple and ghetto solution, not the best one:

<div id="demo">
  <p>{{alert}}</p>
  <p>Old Val: {{ old }}</p>
  <p>New Val: {{ new }}</p>
  <hr />
  <input id="datepicker" v-model="message" lazy>
</div>
  var demo = new Vue({
    el: '#demo',
    data: {
      message: null,
      alert : 0,
      old: 0,
      new: 0,
    },
    watch : {
      'message' : function(newVal, oldVal) {
        if(oldVal !== null)
        {
          this.alert = this.alert + 1;
          this.old = oldVal;
          this.new = newVal;
        }
      }
    }
  });

$(function() {
  $( "#datepicker" ).datepicker();
});

Code Pen for Reference

@PavelCSS
Copy link
Author

It does not work if the value will be written or inserted manually

@ludo237
Copy link

ludo237 commented Dec 25, 2015

@PavelCSS It was a silly solution to point out that the problem is how you are implementing the message callback

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

No branches or pull requests

2 participants