mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
#20689 Adding required attributes for HTML and model
This commit is contained in:
@@ -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"));
|
||||
}
|
||||
|
||||
|
@@ -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; }
|
||||
|
@@ -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 ?? "")
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user