-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix broken validation and multiple custom #12
Changes from all commits
fb746c0
084d022
753d306
ed05ac7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"ignore_dirs": ["tmp"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,8 @@ export default Ember.Mixin.create({ | |
if(Object.keys(errors).length !== 0){ | ||
var stateToTransition = this.get('isNew') ? 'created.uncommitted' : 'updated.uncommitted'; | ||
this.transitionTo(stateToTransition); | ||
store.recordWasInvalid(this, errors); | ||
var recordModel = this.adapterDidInvalidate ? this : this._internalModel; | ||
store.recordWasInvalid(recordModel, errors); | ||
} | ||
return false; | ||
}else{ | ||
|
@@ -47,14 +48,17 @@ export default Ember.Mixin.create({ | |
|
||
/**** Validators ****/ | ||
_validateCustom: function(property, validation){ | ||
var customValidator = this._getCustomValidator(validation); | ||
if (customValidator) { | ||
var passedCustomValidation = customValidator(property, this.get(property), this); | ||
if (!passedCustomValidation) { | ||
this.set('isValidNow', false); | ||
this._addToErrors(property, validation.custom, Messages.customValidationMessage); | ||
} | ||
} | ||
validation = Ember.isArray(validation.custom) ? validation.custom : [validation.custom]; | ||
for (var i = 0; i < validation.length; i++) { | ||
var customValidator = this._getCustomValidator(validation[i]); | ||
if (customValidator) { | ||
var passedCustomValidation = customValidator(property, this.get(property), this); | ||
if (!passedCustomValidation) { | ||
this.set('isValidNow', false); | ||
this._addToErrors(property, validation[i], Messages.customValidationMessage); | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this now ensures that validation is an array or converts it to one. then iterates over it and executes the custom validation as it did before, but for each in the array |
||
}, | ||
_validatePresence: function(property, validation) { | ||
if (Ember.isBlank(this.get(property))){ | ||
|
@@ -248,10 +252,10 @@ export default Ember.Mixin.create({ | |
return validateThis; | ||
}, | ||
_getCustomValidator: function(validation){ | ||
var customValidator = validation.custom; | ||
if (Ember.typeOf(validation.custom) === 'object' && validation.custom.hasOwnProperty('validation')) { | ||
customValidator = validation.custom.validation; | ||
} | ||
var customValidator = validation; | ||
if (Ember.typeOf(validation) === 'object' && validation.hasOwnProperty('validation')) { | ||
customValidator = validation.validation; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this just changes how the function is passed a validation object and returns the custom validation funciton (to account for it being iterated over in the function calling it) |
||
return typeof customValidator === 'function' ? customValidator : false; | ||
}, | ||
_getCustomMessage: function(validationObj,defaultMessage) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
{ | ||
"name": "ember-model-validator", | ||
"dependencies": { | ||
"ember": "1.11.1", | ||
"ember": "1.13.3", | ||
"ember-cli-shims": "ember-cli/ember-cli-shims#0.0.3", | ||
"ember-cli-test-loader": "ember-cli-test-loader#0.1.3", | ||
"ember-data": "1.0.0-beta.16.1", | ||
"ember-load-initializers": "ember-cli/ember-load-initializers#0.1.4", | ||
"ember-data": "1.13.5", | ||
"ember-load-initializers": "ember-cli/ember-load-initializers#0.1.5", | ||
"ember-mocha": "~0.7.0", | ||
"ember-resolver": "~0.1.15", | ||
"ember-resolver": "~0.1.18", | ||
"jquery": "^1.11.1", | ||
"loader.js": "ember-cli/loader.js#3.2.0" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module.exports = { | ||
scenarios: [ | ||
{ | ||
name: 'default', | ||
dependencies: { } | ||
}, | ||
{ | ||
name: 'ember-release', | ||
dependencies: { | ||
'ember': 'components/ember#release' | ||
}, | ||
resolutions: { | ||
'ember': 'release' | ||
} | ||
}, | ||
// { | ||
// name: 'ember-beta', | ||
// dependencies: { | ||
// 'ember': 'components/ember#beta' | ||
// }, | ||
// resolutions: { | ||
// 'ember': 'beta' | ||
// } | ||
// }, | ||
// { | ||
// name: 'ember-canary', | ||
// dependencies: { | ||
// 'ember': 'components/ember#canary' | ||
// }, | ||
// resolutions: { | ||
// 'ember': 'canary' | ||
// } | ||
// } | ||
] | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* global require, module */ | ||
var EmberApp = require('ember-cli/lib/broccoli/ember-addon'); | ||
|
||
module.exports = function(defaults) { | ||
var app = new EmberApp(defaults, { | ||
// Add options here | ||
}); | ||
|
||
/* | ||
This build file specifes the options for the dummy test app of this | ||
addon, located in `/tests/dummy` | ||
This build file does *not* influence how the addon or the app using it | ||
behave. You most likely want to be modifying `./index.js` or app's build file | ||
*/ | ||
|
||
return app.toTree(); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes the errors with 1.13.x and allows for current uses to still work. @esbanarango