Created
March 26, 2013 18:22
-
-
Save tonylukasavage/5247827 to your computer and use it in GitHub Desktop.
Handling model validation errors in Alloy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.index.open(); | |
// create an instance of the model | |
var model = Alloy.createModel('myModel'); | |
// listen for the "error" event | |
model.on('error', function(model, error) { | |
Ti.API.info('error handled: ' + error); | |
}) | |
// attempt to set the doomed model | |
model.set({title:'hi there'}); | |
// title should be undefined | |
Ti.API.info('title: ' + model.get('title')); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Alloy> | |
<Window/> | |
</Alloy> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.definition = { | |
config: { | |
columns: { | |
"title": "TEXT" | |
}, | |
adapter: { | |
type: "sql", | |
collection_name: "myModel" | |
} | |
}, | |
extendModel: function(Model) { | |
_.extend(Model.prototype, { | |
validate: function(attrs, opts) { | |
// let's us know the validation executed | |
Ti.API.info('validate executed'); | |
// always fail validation for the purposes of this test, | |
// normally you would only return a value if your | |
// specific validation failed. Successful validation | |
// return nothing. | |
return "this always fails"; | |
} | |
}); | |
return Model; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment