-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate-on-error.html
More file actions
37 lines (32 loc) · 895 Bytes
/
Copy pathvalidate-on-error.html
File metadata and controls
37 lines (32 loc) · 895 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
<!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 Fruit = Backbone.Model.extend({ // Create model with initialize function
validate: function(options){
if(options.quantity && !_.isNumber(options.quantity)){
return 'Quantity must be number!';
}
}
});
var apple = new Fruit({ // new instance
type: 'apple',
color: 'red'
});
apple.on('error', function (model, error) { // This fires if validation
console.log("Error!");
console.log(error);
});
//apple.set('quantity', 'FFFFFFFFFFFFFFFFF', {validate: true});
apple.set('quantity', 'FFFFFFFFFFFFFFFFF');
//https://stackoverflow.com/questions/14445358/backbone-validate-function-not-getting-called
</script>
</body>
</html>