mercredi 16 mars 2016

How to determine if two properties are false inside one ember computed property?

I have a controller with the following properties and computed properties.

import Ember from 'ember';

export default Ember.Controller.extend({
  emailAddress: '',
  messageBody: '',

  validEmail: Ember.computed.match('emailAddress', /^.+@.+\..+$/),
  validMessage: Ember.computed.gte('messageBody.length', 5),

  enableSend: Ember.computed.and('validEmail', 'validMessage'),
  disableSend: Ember.computed.not('enableSend')
});

This controller is tied to a simple form that has an email input field and text box. I want to check if both the email input and text box are valid before I enable the submit button.

The above code works just fine, however, it seems like there has to be a way to combine the logic in enableSend and disableSend

Apparently you can't chain methods on computed properties but something like this would make sense:

Ember.computed.and.not('validEmail', 'validMessage')

This may be a dumb question but how do I determine if two values are false without having to write two computed properties?




Aucun commentaire:

Enregistrer un commentaire