I have the following view:
@using (Html.BeginForm())
{
<div class="left-column">
@Html.LabelFor(m => m.Expression)
@Html.TextAreaFor(m => m.Expression, new { @spellcheck = "false" })
@Html.EditorFor(m => m.Sku)
</div>
}
With the following JavaScript, which runs every second on a timer:
$("form").validate();
if ($("form").valid()) {
}
Creates the following html for a text area element (the only element requiring validation):
<textarea
data-val="true"
data-val-required="The Expression field is required."
cols="20" rows="2"
id="Expression" name="Expression"
spellcheck="false">
</textarea>
The problem is that validation does nothing unless I manually add class = "required" using browser tools. If I perform this check, and the error message "Expression is required field" appears. Exactly "$ (" form "). Valid ()" always returns true, even if textarea is empty. Since I use anotations that automatically generate data-val attributes, I would like to rely on them. What am I doing wrong?
FYI my script ref :
<script src="/Scripts/modernizr-2.0.6-development-only.js" ...
<script src="/Scripts/jquery-1.6.2.js" ...
<script src="/Scripts/Parser.js" ...
<script src="/Scripts/jquery.unobtrusive-ajax.js" ...
<script src="/Scripts/jquery.validate.js" ...
<script src="/Scripts/jquery.validate.unobtrusive.js" ...