CodesJava

Easy learning with example program codes

Backbone.JS IsValid()


The Backbone.JS IsValid() model is used to check the model state and also to check validations for each attribute.

Syntax:

Model.IsValid 

Example:

<!DOCTYPE html>
<html> 
<head>  
<title> isValid Example</title>  
<script src="https://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"></script>  
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.2/underscore-min.js" type="text/javascript"></script>  
<script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js" type="text/javascript"></script>  
<script type="text/javascript">  
var X = Backbone.Model.extend({  
defaults: {  
Student_Name: '',   
},  
validate: function(attributes) {  
if (attributes.Student_Name == '') {  
document.write("Enter the student name");  
}  
}  
});  
var Y = new X({  
Student_Name: 'Tom'  
});  
document.write("Student_Name is: ", Y.isValid());  
</script>  
</head>  
</html>

Output:

Student_Name is: true

Explanation:
In the above example a value is passed for the ‘Student_Name’ and thus the result is valid.

Please follow and like us:


Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki