mercredi 20 mai 2015

Ember: Setting model to undefined on empty strings

There is a form on the template and when submit is pressed, it hits an action in the controller. When a user types something and deletes it, the binded property will be an empty string instead of undefined. I used the below to solve this problem, but it looks too hackish and unpresentable. Is there something which replaces empty strings on model attributes to undefined? Trying to set it in the model class doesn't work too since I can't get computed properties to work on itself. i.e user: function(){ return undefined if ""}

Here is my controller which handles the form submit:

Controller:
  actions:{
    save: function(){
      if(this.get('user.name')===""){
        this.set('user.name',undefined);
      }
      if(this.get('user.phone')===""){
        this.set('user.phone',undefined);
      }
      if(this.get('user.email')===""){
        this.set('user.email',undefined);
      }
  }
  // Process data
}




Aucun commentaire:

Enregistrer un commentaire