mardi 11 août 2015

How to execute a CP only when the value is changed for the first time?

I'm writing a small validation component that displays an error message if the value is blank/emtpy.

I'm in a bit of a tricky situation. I have a CP that does this:

  isPresenceValid: Ember.computed('value', {
    get() {
      return Ember.isPresent(this.get('value'));
    }
  }),

On page load. value will always be blank. Which means this CP will return false, triggering the template to display an error.

I only want this CP to execute if the value was changed at any point.

Which also means. On page load, if value is blank. Don't display any errors. However, if the user types a value and then removes it. Thats the time the CP executes (returns false).

Any suggestions on how to go about this?

Aucun commentaire:

Enregistrer un commentaire