localisation
parent
c028ec7036
commit
2eddfde6ce
@ -0,0 +1,58 @@
|
||||
using System;
|
||||
|
||||
namespace Yavsc.Attributes.Validation
|
||||
{
|
||||
public class YaValidationAttribute : System.ComponentModel.DataAnnotations.ValidationAttribute
|
||||
{
|
||||
public YaValidationAttribute() : base(()=> Startup.GlobalLocalizer["validationError"])
|
||||
{
|
||||
|
||||
}
|
||||
public override string FormatErrorMessage(string name)
|
||||
{
|
||||
return Startup.GlobalLocalizer[name];
|
||||
}
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)]
|
||||
public class YaRequiredAttribute : YaValidationAttribute
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a flag indicating whether the attribute should allow empty strings.
|
||||
/// </summary>
|
||||
public bool AllowEmptyStrings { get; set; }
|
||||
public YaRequiredAttribute (string msg) : base()
|
||||
{
|
||||
ErrorMessage = msg;
|
||||
}
|
||||
public YaRequiredAttribute ()
|
||||
{
|
||||
this.ErrorMessage = Startup.GlobalLocalizer["RequiredField"];
|
||||
|
||||
}
|
||||
public override bool IsValid(object value) {
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// only check string length if empty strings are not allowed
|
||||
var stringValue = value as string;
|
||||
if (stringValue != null && !AllowEmptyStrings) {
|
||||
return stringValue.Trim().Length != 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public class YaRegularExpression : System.ComponentModel.DataAnnotations.RegularExpressionAttribute {
|
||||
public YaRegularExpression(string pattern): base (pattern)
|
||||
{
|
||||
this.ErrorMessage = pattern;
|
||||
}
|
||||
public override string FormatErrorMessage(string name)
|
||||
{
|
||||
return Startup.GlobalLocalizer[name];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,54 @@
|
||||
@model RegisterViewModel
|
||||
@{
|
||||
ViewData["Title"] = @SR["Register"];
|
||||
}
|
||||
|
||||
@section header{
|
||||
<script src="~/lib/jquery-validation/jquery.validate.js"></script>
|
||||
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"></script>
|
||||
}
|
||||
|
||||
<h2>@ViewData["Title"].</h2>
|
||||
|
||||
<form asp-controller="Account" asp-action="Register" data-toggle="validator" method="post" class="form-horizontal" role="form">
|
||||
<h4>@SR["Create a new account"].</h4>
|
||||
<hr />
|
||||
<div asp-validation-summary="ValidationSummary.All" class="text-danger"></div>
|
||||
<div class="form-group">
|
||||
<label asp-for="UserName" class="col-md-2 control-label"></label>
|
||||
<div class="col-md-10">
|
||||
<input asp-for="UserName" class="form-control" placeholder="Votre nom"/>
|
||||
<span asp-validation-for="UserName" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Email" class="col-md-2 control-label"></label>
|
||||
<div class="col-md-10">
|
||||
<input asp-for="Email" class="form-control" placeholder="votre@@email" />
|
||||
<span asp-validation-for="Email" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Password" class="col-md-2 control-label"></label>
|
||||
<div class="col-md-10">
|
||||
<input asp-for="Password" class="form-control" />
|
||||
<span asp-validation-for="Password" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="ConfirmPassword" class="col-md-2 control-label"></label>
|
||||
<div class="col-md-10">
|
||||
<input asp-for="ConfirmPassword" class="form-control" />
|
||||
<span asp-validation-for="ConfirmPassword" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-md-offset-2 col-md-10">
|
||||
<button type="submit" class="btn btn-default">@SR["Register"]</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@section Scripts {
|
||||
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
|
||||
}
|
||||
Loading…
Reference in New Issue