Skip to content
This repository has been archived by the owner on Jan 31, 2019. It is now read-only.

Commit

Permalink
fixed most of the failing tests - breaking api
Browse files Browse the repository at this point in the history
  • Loading branch information
yonjah committed Aug 12, 2016
1 parent 25277c7 commit 69e526c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,9 @@ import Base from 'ember-validations/validators/base';
import Ember from 'ember';

export default Base.extend({
init: function() {
pushDependentValidationKeys: function() {
// this call is necessary, don't forget it!
this._super();

this.dependentValidationKeys.pushObject(this.options.alsoWatch);
},
call: function() {
Expand All @@ -388,8 +387,8 @@ export default Base.extend({
});
```

The `init` function is given access to the `this.options` which is simply
a POJO of the options passed to the validator.
The `pushDependentValidationKeys` function is called during `init` and is given access
to the `this.options` which is simply a POJO of the options passed to the validator.
`dependentValidationKeys` is the collection of paths relative to
`this.model` that will be observed for changes. If any changes occur on
any given path the validator will automatically trigger.
Expand Down
5 changes: 3 additions & 2 deletions addon/validators/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ export default Ember.Object.extend({
unless: get(this, 'options.unless')
};
this.dependentValidationKeys.pushObject(this.property);
this.pushConditionalDependentValidationKeys();
// this.model.addObserver(this.property, this, this._validate);
this.pushDependentValidationKeys();
this.addObserversForDependentValidationKeys();
},
addObserversForDependentValidationKeys: function() {
this.dependentValidationKeys.forEach(function(key) {
this.model.addObserver(key, this, this._validate);
}, this);
},
pushConditionalDependentValidationKeys: function() {
pushDependentValidationKeys: function() {
Ember.A(['if', 'unless']).forEach((conditionalKind) => {
const conditional = this.conditionals[conditionalKind];
if (typeof(conditional) === 'string' && typeof(this.model[conditional]) !== 'function') {
Expand Down
5 changes: 4 additions & 1 deletion addon/validators/local/confirmation.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ export default Base.extend({
this.originalProperty = this.property;
this.property = this.property + 'Confirmation';
this._super();
this.dependentValidationKeys.pushObject(this.originalProperty);
/*jshint expr:true*/
if (this.options === true) {
set(this, 'options', { attribute: this.originalProperty });
set(this, 'options', { message: Messages.render('confirmation', this.options) });
}
},
pushDependentValidationKeys: function () {
this._super();
this.dependentValidationKeys.pushObject(this.originalProperty);
},
call: function() {
var original = get(this.model, this.originalProperty);
var confirmation = get(this.model, this.property);
Expand Down

0 comments on commit 69e526c

Please sign in to comment.