@{
ViewBag.Title = "Validation engine integration";
}
@section CssImport
{
<link href="@Url.Content("~/Scripts/validationEngine/validationEngine.jquery.css")" rel="stylesheet" type="text/css" />
}
@section JavascriptImport
{
<script type="text/javascript" src="@Url.Content("~/Scripts/validationEngine/jquery.validationEngine.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/validationEngine/jquery.validationEngine-en.js")"></script>
}
<div id="StudentTableContainer"></div>
<script type="text/javascript">
$(document).ready(function () {
$('#StudentTableContainer').jtable({
title: 'Student List',
paging: true, //Enable paging
sorting: true, //Enable sorting
defaultSorting: 'Name ASC',
actions: {
listAction: '@Url.Action("StudentList")',
deleteAction: '@Url.Action("DeleteStudent")',
updateAction: '@Url.Action("UpdateStudent")',
createAction: '@Url.Action("CreateStudent")'
},
fields: {
StudentId: {
key: true,
create: false,
edit: false,
list: false
},
Name: {
title: 'Name',
width: '15%'
},
EmailAddress: {
title: 'Email address',
list: false
},
Password: {
title: 'User Password',
type: 'password',
list: false
},
Gender: {
title: 'Gender',
width: '12%',
options: { 'M': 'Male', 'F': 'Female' }
},
CityId: {
title: 'Living city',
width: '15%',
options: '@Url.Action("GetCityOptions")'
},
BirthDate: {
title: 'Birth date',
width: '18%',
type: 'date',
displayFormat: 'yy-mm-dd'
},
Education: {
title: 'Education',
list: false,
type: 'radiobutton',
options: { '1': 'Primary school', '2': 'High school', '3': 'University' }
//,setOnTextClick: false //Activate this line to not to change checkbox when clicked to radio button's text
},
About: {
title: 'About this person',
type: 'textarea',
list: false
},
IsActive: {
title: 'Status',
width: '10%',
type: 'checkbox',
values: { 'false': 'Passive', 'true': 'Active' },
defaultValue: 'true'
//,formText: 'User is active' //Activate this line to make checkbox text fixed in edit/create form
//,setOnTextClick: false //Activate this line to not to change checkbox when clicked to checkbox's text
},
RecordDate: {
title: 'Record date',
width: '18%',
type: 'date',
displayFormat: 'yy-mm-dd',
create: false,
edit: false
}
},
formCreated: function (event, data) {
data.form.find('input[name="Name"]').addClass('validate[required]');
data.form.find('input[name="EmailAddress"]').addClass('validate[required,custom[email]]');
data.form.find('input[name="Password"]').addClass('validate[required]');
data.form.find('input[name="BirthDate"]').addClass('validate[required,custom[date]]');
data.form.find('input[name="Education"]').addClass('validate[required]');
data.form.validationEngine();
},
formSubmitting: function (event, data) {
return data.form.validationEngine('validate');
},
formClosed: function (event, data) {
data.form.validationEngine('hide');
data.form.validationEngine('detach');
}
});
//Load student list from server
$('#StudentTableContainer').jtable('load');
});
</script>
<br />
<hr />
<h3>
HTML code</h3>
<pre class="brush:html"><!-- Import CSS file for validation engine (in Head section of HTML) -->
<link href="/Scripts/validationEngine/validationEngine.jquery.css" rel="stylesheet" type="text/css" />
<!-- Import Javascript files for validation engine (in Head section of HTML) -->
<script type="text/javascript" src="/Scripts/validationEngine/jquery.validationEngine.js"></script>
<script type="text/javascript" src="/Scripts/validationEngine/jquery.validationEngine-en.js"></script>
<!-- Container for jTable -->
<div id="StudentTableContainer"></div></pre>
<h3>
Javascript code</h3>
<pre class="brush:js; highlight:[79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96]"><script type="text/javascript">
$(document).ready(function () {
$('#StudentTableContainer').jtable({
title: 'Student List',
paging: true, //Enable paging
sorting: true, //Enable sorting
defaultSorting: 'Name ASC',
actions: {
listAction: '/Demo/StudentList',
deleteAction: '/Demo/DeleteStudent',
updateAction: '/Demo/UpdateStudent',
createAction: '/Demo/CreateStudent'
},
fields: {
StudentId: {
key: true,
create: false,
edit: false,
list: false
},
Name: {
title: 'Name',
width: '15%'
},
EmailAddress: {
title: 'Email address',
list: false
},
Password: {
title: 'User Password',
type: 'password',
list: false
},
Gender: {
title: 'Gender',
width: '12%',
options: { 'M': 'Male', 'F': 'Female' }
},
CityId: {
title: 'Living city',
width: '15%',
options: '/Demo/GetCityOptions'
},
BirthDate: {
title: 'Birth date',
width: '18%',
type: 'date',
displayFormat: 'yy-mm-dd'
},
Education: {
title: 'Education',
list: false,
type: 'radiobutton',
options: { '1': 'Primary school', '2': 'High school', '3': 'University' }
},
About: {
title: 'About this person',
type: 'textarea',
list: false
},
IsActive: {
title: 'Status',
width: '10%',
type: 'checkbox',
values: { 'false': 'Passive', 'true': 'Active' },
defaultValue: 'true'
},
RecordDate: {
title: 'Record date',
width: '18%',
type: 'date',
displayFormat: 'yy-mm-dd',
create: false,
edit: false
}
},
//Initialize validation logic when a form is created
formCreated: function (event, data) {
data.form.find('input[name="Name"]').addClass('validate[required]');
data.form.find('input[name="EmailAddress"]').addClass('validate[required,custom[email]]');
data.form.find('input[name="Password"]').addClass('validate[required]');
data.form.find('input[name="BirthDate"]').addClass('validate[required,custom[date]]');
data.form.find('input[name="Education"]').addClass('validate[required]');
data.form.validationEngine();
},
//Validate form when it is being submitted
formSubmitting: function (event, data) {
return data.form.validationEngine('validate');
},
//Dispose validation logic when form is closed
formClosed: function (event, data) {
data.form.validationEngine('hide');
data.form.validationEngine('detach');
}
});
//Load student list from server
$('#StudentTableContainer').jtable('load');
});
</script></pre>
<h3>
Server side code</h3>
@Html.Partial("_PagedAndSortedServerSideCodes")