So I'm wondering if there is a computed string property that negates the current boolean value of a property. For example, in the computed property 'isDisabledSubmit' below, I added an exclamation mark in front of isValidEmail and isValidMessage in attempt to negate the property value. This doesn't work, but you can probably assume what I'm trying to accomplish. I could get it to work by adding two extra properties isInvalidEmail and isInvalidMessage, but this seems a bit excessive in a large app... Is there a way to do a not and and a not or/ negate a property inside an and/or?
export default Ember.Controller.extend({
contactForm: false,
contactEmail: '',
contactMessage: '',
isValidEmail: Ember.computed.match( 'contactEmail', /^.+@.+\..+$/ ),
isValidMessage: Ember.computed.gte('contactMessage.length', 10),
isDisabledSubmit: Ember.computed.or( '!isValidEmail', '!isValidMessage')
});
Possible, but tedious solution
export default Ember.Controller.extend({
contactForm: false,
contactEmail: '',
contactMessage: '',
isValidEmail: Ember.computed.match( 'contactEmail', /^.+@.+\..+$/ ),
isValidMessage: Ember.computed.gte('contactMessage.length', 10),
//Add negated version of previous properties...tedious approach...
isInvalidEmail: Ember.computed.not('isValidEmail'),
isInvalidMessage: Ember.computed.not('isValidMessage'),
//
isDisabledSubmit: Ember.computed.or( 'isInvalidEmail', 'isInvalidMessage')
});
Aucun commentaire:
Enregistrer un commentaire