-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidation-complex.html
More file actions
38 lines (38 loc) · 1.06 KB
/
validation-complex.html
File metadata and controls
38 lines (38 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script src="jquery-1.11.2.js"></script>
<script src="underscore.js"></script>
<script src="backbone.js"></script>
<script>
var Todo = Backbone.Model.extend({
defaults: {
completed: false //,
//title: "Hello World" //This will cause validation to return true. Don't forget the comma ;)
},
validate: function(attributes){
//console.log('Validation Ran!');
if(attributes.title === undefined){
//return 'Title undefined!';
console.log('Title is undefined!');
}
},
initialize: function(){
console.log('This model has been initialized.');
this.on("invalid", function(model, error){
console.log('ERROR: ' + error);
});
}
});
var myTodo = new Todo();
myTodo.set('completed', true, {validate: true}); // Runs validation, because title isn't set
myTodo.set({title: 'Russell'}, {validate: true});
console.log('title: ' + myTodo.get('title'));
console.log('completed: ' + myTodo.get('completed'));
</script>
</body>
</html>