Note that there are some explanatory texts on larger screens.

plurals
  1. PORectify the input at client side using RemoteValidation
    primarykey
    data
    text
    <p>Is there any possibility of rectifying the input at client side using Remote Validation? For example, the user will enter the date as <strong>010101</strong> which means <strong>01-Jan-2001</strong>, can Remote Validation reflect/pass the rectified value (<strong>010101</strong> into <strong>01-Jan-2001</strong>) at/to client side?</p> <p>I have a scenario where i have JS to format the input into correct date format. Later on i had to use RemoteValidation. My remote validation receives date in <strong>ddmmyy</strong> format (RemoteValidation gets called before JS), it first converts it into correct date and then perform validation, and then my JS does not get called at all and so <strong>010101</strong> is not get converted into <strong>01-Jan-2001</strong>.</p> <p><strong>Edit</strong></p> <p>There are two things i would like to get help for</p> <p>1- Is there anyway a remote validation function can modify the model/data passed to it for validation and then pass it back to the view so that user can see the modified version of the model/data</p> <p>[<strong>Deleted</strong>:2- I have JavaScript for a date field which formats the date when focus is lost. It is working fine. When i used Remote validation along with JS, the script does not get called at all.]</p> <p><strong>Edit</strong></p> <p><strong>Model</strong></p> <pre><code>public class master { public string sometext { get; set; } public child mychild { get; set; } } public class child { public child() { thedate = DateTime.MaxValue; } [Remote("ValidateDate", "Test", ErrorMessage = "Invalid Date")] [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:mm/dd/yyyy}", NullDisplayText = "Enter Date")] public DateTime? thedate { get; set; } } </code></pre> <p><strong>View</strong></p> <pre><code>@model Models.master @using Web.Framework @{ Layout = null; } &lt;html&gt; &lt;head&gt; &lt;title&gt;Test - My ASP.NET MVC Application&lt;/title&gt; &lt;script src="@Url.Scripts("jquery-1.7.1.min.js")" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="@Url.Scripts("jquery-ui-1.8.11.js")" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="@Url.Scripts("modernizr-2.0.6-development-only.js")" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="@Url.Scripts("AjaxLogin.js")" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="@Url.Scripts("jquery.validate.min.js")" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="@Url.Scripts("jquery.validate.unobtrusive.min.js")" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="@Url.Scripts("jquery.unobtrusive-ajax.min.js")" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="@Url.Scripts("MicrosoftAjax.js")" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="@Url.Scripts("MicrosoftMvcAjax.js")" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="@Url.Scripts("myScripts.js")" type="text/javascript"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; @using (Html.BeginForm("testSubmit", "Test")) { @Html.LabelFor(m =&gt; m.sometext) &lt;br /&gt; @Html.TextBoxFor(m =&gt; m.sometext) &lt;br /&gt; @Html.LabelFor(m =&gt; m.mychild.thedate) &lt;br /&gt; @Html.TextBoxFor(m =&gt; m.mychild.thedate, new { onblur = "doDate(this, '');" }) @Html.ValidationMessageFor(m =&gt; m.mychild.thedate) &lt;br /&gt; &lt;input type="submit" value = "Submit me" /&gt; } &lt;/body&gt;&lt;/html&gt; </code></pre> <p><strong>Controller</strong></p> <pre><code>public ActionResult testSubmit(master model) { @ViewBag.Message = "OK"; return View("response"); } public JsonResult ValidateDate(DateTime? thedate) { return Json(HttpContext.Request.QueryString["mychild.thedate"].ToString(), JsonRequestBehavior.AllowGet); } </code></pre> <p>My remote validator always receives null in <code>thedate</code>, but i can access the value from query string but the value is unformatted i.e. Remote validation gets called before JS which means i have to format the date first in remote function and then validate, once validated then this input is formatted again by JS and both have to be synced. </p> <p>Now, how can i get the formatted value in Remote function OR pass the formatted value from Remote function to the View ?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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