lundi 30 novembre 2015

Allowing buttons to be clicked if one or more checkbox are clicked

I have in my page two buttons, edit and delete. Edit only should be clicked if one checkbox are clicked, and delete should be clicked if one or more buttons are clicked.

I think my solutions is wrong:

<li class="controller {{if editRecord '' 'controller__item--disabled' }}">Edit</li>
<li class="controller {{if destroyRecord '' 'controller__item--disabled'}}">Delete</li>

And i'm observing two times model.@each.checked:

editRecord: Ember.computed('model.@each.checked', function() {
  let count = 0;
  this.get('model').forEach((item) => {
      if (item.get('checked')) {
        count +=1;
      }
  });

   if (count === 1) return true;
   return false;
});


deleteRecord: Ember.computed('model.@each.checked', function() {
  let count = 0;
  this.get('model').forEach((item) => {
      if (item.get('checked')) {
        count +=1;
      }
  });

   if (count >= 1) return true;
   return false;
});

The problem is.. if i have 10 buttons and i need check each one.. this will be unmaintainable..

Thanks.




Aucun commentaire:

Enregistrer un commentaire