Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC5 textarea not outlined in red on validation error

I am using ASP.NET MVC5 with Bootstrap, and have the following in a Razor view for a contact form...

@using (Html.BeginForm("Contact", "Home", FormMethod.Post, new {role = "form"})) {
<div class="form-group">
@Html.LabelFor(model => model.theirname)
@Html.TextBoxFor(model => model.theirname, new {@class = "form-control", placeholder = "Enter your name"})
<div>@Html.ValidationMessageFor(model => model.theirname, "You must enter your name")</div>
  @Html.LabelFor(model => model.theiremail)
  @Html.TextBoxFor(model => model.theiremail, new {@class = "form-control", placeholder = "Enter your email"})
  <div>@Html.ValidationMessageFor(model => model.theiremail, "You must enter your email address")</div>
  @Html.LabelFor(model => model.message)
  @Html.TextAreaFor(model => model.message, new {@class = "form-control", placeholder = "Enter message", cols = 40, rows = 5})
  <div>@Html.ValidationMessageFor(model => model.message, "You must enter a message")</div>
  <input type="checkbox" id="copytome" name="copytome" checked="@Model.copytome" /> <label for="copytome">Send me a copy of the message</label>
  <div><input type="submit" value="Send" class="btn btn-default" /></div>
</div>
}

If the user clicks the submit button without filling in their name or email address, the validation message is displayed correctly, and the textboxes are outlined in red.

However, the textarea doesn't get outlined, although the validation message is shown... enter image description here

Here is the generated HTML...

<form action="/Home/Contact" method="post" role="form">
<div class="form-group">
<label for="theirname">Your name</label>
<input class="input-validation-error form-control" data-val="true" data-val-required="The Your name field is required." id="theirname" name="theirname" placeholder="Enter your name" type="text" value="" />
<div><span class="field-validation-error" data-valmsg-for="theirname" data-valmsg-replace="false">You must enter your name</span></div>
<label for="theiremail">Your email</label>
<input class="input-validation-error form-control" data-val="true" data-val-required="The Your email field is required." id="theiremail" name="theiremail" placeholder="Enter your email" type="text" value="" />
<div><span class="field-validation-error" data-valmsg-for="theiremail" data-valmsg-replace="false">You must enter your email address</span></div>
<label for="message">Message</label>
<textarea class="input-validation-error form-control" cols="40" data-val="true" data-val-required="The Message field is required." id="message" name="message" placeholder="Enter message" rows="5">
</textarea>
<div><span class="field-validation-error" data-valmsg-for="message" data-valmsg-replace="false">You must enter a message</span></div>
<input type="checkbox" id="copytome" name="copytome" /> <label for="copytome">Send me a copy of the message</label>
<div><input type="submit" value="Send" class="btn btn-default" /></div>
</div>
</form>

Anyone any idea why the textarea isn't outlined in red?

like image 587
Avrohom Yisroel Avatar asked Jul 30 '14 14:07

Avrohom Yisroel


1 Answers

Presumably bootstrap doesn't include a style rule for invalid textarea elements. You could fix it by adding the following to your stylesheet:

 textarea.input-validation-error {
      border-color: red;
 }
like image 142
Ben Griffiths Avatar answered Sep 28 '22 07:09

Ben Griffiths