Note that there are some explanatory texts on larger screens.

plurals
  1. POMake manual servervalidation and color textfield if failed
    text
    copied!<p>I am trying to change the color of a textfield to red if a serverside validation fails.</p> <p>If result is True or False nothing happens</p> <p>JQuery</p> <pre><code> $('.datein').change(function () { //send servervalidering ajax var data = { dateOut: $('#resource_dateout').val(), dateHourOut: $('#resource_hourout').val(), dateMinuteOut: $('#resource_minuteout').val(), dateIn: $('#resource_datein').val(), dateHourIn: $('#resource_hourin').val(), dateMinuteIn: $('#resource_minutein').val() }; $.post("Resource/isDateValid", data, ajaxsuccess); }); function ajaxsuccess(result) { if ($('.datein').hasClass('.resourceerror')) { if (result == "True") { $('.datein').removeClass('.resourceerror'); } } else if (result == "False") { $('.datein').addClass('.resourceerror'); } } </code></pre> <p>Html</p> <pre><code> &lt;span class="editor-field"&gt; @Html.TextBoxFor(m =&gt; m.DateIn.Date, new { @Id = "resource_datein", @class = "datepicker datein", maxlength = "10" }) @Html.TextBoxFor(m =&gt; m.DateIn.Hour, new { @Id = "resource_hourin", @class = "datein", maxlength = "2" }) : @Html.TextBoxFor(m =&gt; m.DateIn.Minute, new { @Id = "resource_minutein", @class = "datein", maxlength = "2" }) &lt;/span&gt; &lt;span&gt; @Html.ValidationMessageFor(m =&gt; m.DateIn.Date) @Html.ValidationMessageFor(m =&gt; m.DateIn.Hour) @Html.ValidationMessageFor(m =&gt; m.DateIn.Minute) &lt;/span&gt; </code></pre> <p>Is there a way I can just toggle a validation instead? My code dont work, I am 100% sure the Ajax call either returns "True" or "False"</p> <p>Edit: When accessing the css classes I wrote hasClass('.classname') instead of hasClass('classname')</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload