javascript - The field must be a date - DatePicker validation fails in mvc -


i'm getting validation message following when submit form call post action (method)

the field patientdob must date.

my model is

[required(errormessage = "patient dob required")] [datatype(datatype.date)] [displayformat(dataformatstring = "{0:yyyy-mm-dd}", applyformatineditmode = true)] 

my view following,

@{     layout = "~/views/shared/_formlayout.cshtml";     var dob= model.patientdob == datetime.minvalue ? string.empty : model.patientdob.tostring("yyyy-mm-dd");     var phoneno = model.patientphoneno == 0 ? string.empty : model.patientphoneno.tostring(); }  <div class="row">     <div class="col-lg-2">         <label class="m-t-sm font-bold">date of birth:</label>     </div>     <div class="col-lg-2">         @html.textboxfor(a => a.patientdob, "{0:yyyy-mm-dd}", new {@class = "bg-empty txtline input-s-sm", value = @dob})     </div> </div> 

note: using jquery datepicker fields jquery code

<script type="text/javascript">     $(document).ready(function () {         $('#patientdob').datepicker({             dateformat: "yy-mm-dd",             showstatus: true,             showweeks: true,             currenttext: 'now',             autosize: true,             gotocurrent: true,             showanim: 'blind',             highlightweek: true         });     }); </script> 

earlier working fine have changed nothing in code showing validation problem.i have tried solution given here solution tried.but none solved problem.stackoverflow-question

that's old problem. ultimate solution - use globalize.js library , change jquery validation methods globalize methods:

$(document).ready(function () {     globalize.culture("pl-pl"); //not sure it's locale, maby need other     $.validator.methods.date = function (value, element) {         return this.optional(element) || globalize.parsedate(value);     }; }); 

you should init script after jquery validation load.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -