-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.html
More file actions
38 lines (35 loc) · 882 Bytes
/
model.html
File metadata and controls
38 lines (35 loc) · 882 Bytes
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
<html>
<head>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/backbone.js/1.2.2/backbone-min.js"></script>
</head>
<body>
<div>
</div>
</body>
<script>
var Model = Backbone.Model.extend({
url: "/users",
defaults: {
first: "Bob",
last: "Tonks",
email: "bob@bob.com"
},
validate: function(atts, ops) {
if (atts.first === "Steve") {
return "No Steve's allowed!";
}
}
});
var m = new Model();
// only on change first name
m.on("change:first", function() {
console.log(m.isValid());
console.log(m.validationError);
});
console.log(m.isValid());
console.log(m.validationError);
m.set("first", "Steve");
</script>
</html>