#20689 Adding required attributes for HTML and model

This commit is contained in:
Nicholas Mayne
2014-05-11 22:36:43 +01:00
parent 74026ec729
commit e1eebc200b
3 changed files with 7 additions and 7 deletions

View File

@@ -29,11 +29,11 @@ namespace Orchard.Comments.Controllers {
var comment = Services.ContentManager.New<CommentPart>("Comment");
var editorShape = Services.ContentManager.UpdateEditor(comment, this);
if (!ModelState.IsValidField("Comments.Author") && Services.WorkContext.CurrentUser == null) {
if (!ModelState.IsValidField("Comments.Author")) {
Services.Notifier.Error(T("Name is mandatory and must have less than 255 chars"));
}
if (!ModelState.IsValidField("Comments.Email") && Services.WorkContext.CurrentUser == null) {
if (!ModelState.IsValidField("Comments.Email")) {
Services.Notifier.Error(T("Email is invalid or is longer than 255 chars"));
}

View File

@@ -12,7 +12,7 @@ namespace Orchard.Comments.Models {
public LazyField<ContentItem> CommentedOnContentItemField { get { return _commentedOnContentItem; } }
public LazyField<ContentItemMetadata> CommentedOnContentItemMetadataField { get { return _commentedOnContentItemMetadata; } }
[StringLength(255)]
[Required, StringLength(255)]
public string Author {
get { return Record.Author; }
set { Record.Author = value; }
@@ -31,7 +31,7 @@ namespace Orchard.Comments.Models {
set { Record.UserName = value; }
}
[RegularExpression(@"^(?![\.@])(""([^""\r\\]|\\[""\r\\])*""|([-a-z0-9!#$%&'*+/=?^_`{|}~]|(?<!\.)\.)*)(?<!\.)@[a-z0-9][\w\.-]*[a-z0-9]\.[a-z][a-z\.]*[a-z]$")]
[Required, RegularExpression(@"^(?![\.@])(""([^""\r\\]|\\[""\r\\])*""|([-a-z0-9!#$%&'*+/=?^_`{|}~]|(?<!\.)\.)*)(?<!\.)@[a-z0-9][\w\.-]*[a-z0-9]\.[a-z][a-z\.]*[a-z]$")]
public string Email {
get { return Record.Email; }
set { Record.Email = value; }

View File

@@ -7,11 +7,11 @@
<ol>
<li>
@Html.LabelFor(m => m.Author, T("Name"))
@Html.TextBoxFor(m => m.Author)
@Html.TextBoxFor(m => m.Author, new { required = "required" })
</li>
<li>
@Html.LabelFor(m => m.Email, T("Email"))
@Html.TextBoxFor(m => m.Email)
@Html.TextBoxFor(m => m.Email, new { required = "required" })
</li>
<li>
@Html.LabelFor(m => m.SiteName, T("Url"))
@@ -21,7 +21,7 @@
</fieldset>
}
else {
@Html.Hidden("Name", WorkContext.CurrentUser.UserName ?? "")
@Html.Hidden("Author", WorkContext.CurrentUser.UserName ?? "")
@Html.Hidden("Email", WorkContext.CurrentUser.Email ?? "")
}