Skip to content

labels now show up in red. #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ deploy-to-ec2*

#Monotouch garbage
*.pidb

#VS11 garbage
_UpgradeReport_Files/
Backup*/
UpgradeLog*.*
4 changes: 2 additions & 2 deletions BlankMVCProject/BlankMVCProject.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 11
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlankMVCProject", "BlankMVCProject\BlankMVCProject.csproj", "{4A957ECA-37F7-4308-A923-195A152EA351}"
EndProject
Global
Expand Down
19 changes: 18 additions & 1 deletion BlankMVCProject/BlankMVCProject/BlankMVCProject.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand All @@ -15,6 +16,15 @@
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<MvcBuildViews>false</MvcBuildViews>
<UseIISExpress>false</UseIISExpress>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>4.0</OldToolsVersion>
<IISExpressSSLPort />
<IISExpressAnonymousAuthentication />
<IISExpressWindowsAuthentication />
<IISExpressUseClassicPipelineMode />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -138,12 +148,14 @@
<Content Include="README.jQuery.vsdoc.txt" />
<Content Include="Scripts\bootstrap.js" />
<Content Include="Scripts\bootstrap.min.js" />
<Content Include="Scripts\bootstrap.mvcvalidation.js" />
<Content Include="Scripts\jquery-1.7.1-vsdoc.js" />
<Content Include="Scripts\jquery-1.7.1.js" />
<Content Include="Scripts\jquery-1.7.1.min.js" />
<Content Include="Scripts\jquery-ui-1.8.17.js" />
<Content Include="Scripts\jquery-ui-1.8.17.min.js" />
<Content Include="Scripts\jquery.validate-vsdoc.js" />
<Content Include="Scripts\jquery.validate.hooks.js" />
<Content Include="Scripts\jquery.validate.js" />
<Content Include="Scripts\jquery.validate.min.js" />
<Content Include="Scripts\modernizr-2.0.6-development-only.js" />
Expand Down Expand Up @@ -213,8 +225,13 @@
<None Include="CodeTemplates\AddView\CSHTML\Empty.tt" />
<None Include="CodeTemplates\AddView\CSHTML\List.tt" />
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ if (mvcHost.ReferenceScriptLibraries) {
#>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.hooks.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/bootstrap.mvcvalidation.js")" type="text/javascript"></script>

<#
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ if (mvcHost.ReferenceScriptLibraries) {
#>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.hooks.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/bootstrap.mvcvalidation.js")" type="text/javascript"></script>

<#
}
Expand Down
10 changes: 10 additions & 0 deletions BlankMVCProject/BlankMVCProject/Scripts/bootstrap.mvcvalidation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
$(function () {
$('form').addTriggersToJqueryValidate().triggerElementValidationsOnFormValidation();
$('input[data-val]').elementValidation(function (element, result) {
var el = $(element);
if (!result)
el.parents('div.control-group').addClass('error');
else
el.parents('div.control-group').removeClass('error');
});
});
125 changes: 125 additions & 0 deletions BlankMVCProject/BlankMVCProject/Scripts/jquery.validate.hooks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
(function ($) {

$.fn.addTriggersToJqueryValidate = function () {

// Loop thru the elements that we jQuery validate is attached to
// and return the loop, so jQuery function chaining will work.
return this.each(function () {
var form = $(this);

// Grab this element's validator object (if it has one)
var validator = form.data('validator');

// Only run this code if there's a validator associated with this element
if (!validator)
return;

// Only add these triggers to each element once
if (form.data('jQueryValidateTriggersAdded'))
return;
else
form.data('jQueryValidateTriggersAdded', true);

// Override the function that validates the whole form to trigger a
// formValidation event and either formValidationSuccess or formValidationError
var oldForm = validator.form;
validator.form = function () {
var result = oldForm.apply(this, arguments);
var form = this.currentForm;
$(form).trigger((result == true) ? 'formValidationSuccess' : 'formValidationError', form);
$(form).trigger('formValidation', [form, result]);
return result;
};

// Override the function that validates the whole element to trigger a
// elementValidation event and either elementValidationSuccess or elementValidationError
var oldElement = validator.element;
validator.element = function (element) {
var result = oldElement.apply(this, arguments);
$(element).trigger((result == true) ? 'elementValidationSuccess' : 'elementValidationError', element);
$(element).trigger('elementValidation', [element, result]);
return result;
};
});
};

/* Below here are helper methods for calling .bind() for you */

$.fn.extend({

// Wouldn't it be nice if, when the full form's validation runs, it triggers the
// element* validation events? Well, that's what this does!
//
// NOTE: This is VERY coupled with jquery.validation.unobtrusive and uses its
// element attributes to figure out which fields use validation and
// whether or not they're currently valid.
//
triggerElementValidationsOnFormValidation: function () {
return this.each(function () {
$(this).bind('formValidation', function (e, form, result) {
$(form).find('*[data-val=true]').each(function (i, field) {
if ($(field).hasClass('input-validation-error')) {
$(field).trigger('elementValidationError', field);
$(field).trigger('elementValidation', [field, false]);
} else {
$(field).trigger('elementValidationSuccess', field);
$(field).trigger('elementValidation', [field, true]);
}
});
});
});
},

formValidation: function (fn) {
return this.each(function () {
$(this).bind('formValidation', function (e, element, result) { fn(element, result); });
});
},

formValidationSuccess: function (fn) {
return this.each(function () {
$(this).bind('formValidationSuccess', function (e, element) { fn(element); });
});
},

formValidationError: function (fn) {
return this.each(function () {
$(this).bind('formValidationError', function (e, element) { fn(element); });
});
},

formValidAndInvalid: function (valid, invalid) {
return this.each(function () {
$(this).bind('formValidationSuccess', function (e, element) { valid(element); });
$(this).bind('formValidationError', function (e, element) { invalid(element); });
});
},

elementValidation: function (fn) {
return this.each(function () {
$(this).bind('elementValidation', function (e, element, result) { fn(element, result); });
});
},

elementValidationSuccess: function (fn) {
return this.each(function () {
$(this).bind('elementValidationSuccess', function (e, element) { fn(element); });
});
},

elementValidationError: function (fn) {
return this.each(function () {
$(this).bind('elementValidationError', function (e, element) { fn(element); });
});
},

elementValidAndInvalid: function (valid, invalid) {
return this.each(function () {
$(this).bind('elementValidationSuccess', function (e, element) { valid(element); });
$(this).bind('elementValidationError', function (e, element) { invalid(element); });
});
}

});

})(jQuery);
3 changes: 3 additions & 0 deletions BlankMVCProject/BlankMVCProject/Views/Account/Register.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
</p>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.hooks.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/bootstrap.mvcvalidation.js")" type="text/javascript"></script>

@using (Html.BeginForm())
{
@Html.ValidationSummary(true, "Account creation was unsuccessful. Please correct the errors and try again.")
Expand Down