Validation Settings
The Mvc Controls Toolkit works both with the old Ajax Microsoft Validation and with the Unobtrusive Validation.
The right order of the js files to be included for the old Ajax Validation is:
<script type='text/javascript' src="../../Scripts/MicrosoftAjax.js"></script>
<script type='text/javascript' src="../../Scripts/MicrosoftMvcAjax.js"></script>
<script type='text/javascript' src="../../Scripts/MicrosoftMvcValidation.js"></script>
<script type='text/javascript' src="../../Scripts/MVCControlToolkit.Controls-x.x.x.min.js"></script>
While the right order for the Unobtrusive Validation is:
<script type='text/javascript' src="../../Scripts/jquery-1.7.1.min.js"></script>
<script type='text/javascript' src="../../Scripts/jquery-ui-1.8.9.custom.min.js"></script>
<script type='text/javascript' src="../../Scripts/jquery.validate-1.8.1.min.js"></script>
<script type='text/javascript' src="../../Scripts/jquery.validate.unobtrusive.min.js"></script>
<script type='text/javascript' src="../../Scripts/jquery.unobtrusive-ajax.min.js"></script>
<script type='text/javascript' src="../../Scripts/MVCControlToolkit.Controls-x.x.x.min.js"></script>
<script type='text/javascript' >
$.validator.setDefaults({
ignore: "not([data-elementispart]):hidden"
});
</script>
Where:
<script type='text/javascript' src="../../Scripts/globalize.min.js"></script>
<%: Html.GlobalizationScript() %>
is needed only if you would like to globalize your application or if you would like to use it with a culture different from the English culture. For more information see
Globalization.
<script type='text/javascript' >
$.validator.setDefaults({
ignore: "not([data-elementispart]):hidden"
});
</script>
Is needed if you use a version of the validation library greater than 1.8. Infact, starting from the above release the validation library doesn't validate
:Hidden fields as default. Since, some Mvc Controls Toolkit Controls that need to be validated use
Hidden input to store values, we must enable validation for them. Since all parts of a control are marked with the
data-elementispart Html5 attribute the above javascript script restores validation just for all of them.
However, if you would like to restore validation for all :Hidden fields you might substitute the above script with:
<script type='text/javascript' >
$.validator.setDefaults({
ignore: ""
});
</script>
This is usefull if you put fields to be validated into Widgets like the
jQUery UI Tabs that hide all tabs that are not selected.