c# - ASP MVC DateTime Validation Issue in IE9 -
i working on fixing bug on application developed asp.net mvc razor , angular.
the problem in ie9 datetime value not displayed @ in input box.
i have tracked down "required" keeps adding required="required".
the incidentdate property in model nullable datetime.
public system.datetime ? incidentdate { get; set; }
it works fine in ie10+,ff , chrome in ie 9 datetime not displaying @ all.
if edit markup html , remove required tag datetime value appears in input box.
i tried adding following line in application_start still same issue:
modelvalidatorproviders.providers.clear(); modelvalidatorproviders.providers.add(new dataannotationsmodelvalidatorprovider());
here markup generated in ie
<input name="incident.incidentdate" class="form-control ng-valid ng-isolate-scope input-validation-error ng-touched ng-dirty ng-valid-parse" id="incident_incidentdate" aria-invalid="true" aria-required="true" aria-describedby="incident_incidentdate-error" type="text" placeholder="dd/mm/yyyy h:mm am/pm" value="22/09/2015 2:00:00 pm" ng-model="model.incident.incidentdate" use-datepicker="true" format="dd/mm/yyyy hh:mm a" date-time-picker="" data-val-required="the date , time of incident field required." data-val="true" use-timepicker="true" data-val-daterange-min="1753-01-01t00:00:00" data-val-daterange-max="9999-12-31t23:59:59" data-val-daterange="the field date , time of incident invalid.">
if has solution please let me know. thank you.
digging bit deeper found there custom datetime editor template. started debugging , seems when not add attributes works fine in ie 9
datetime? value = null; if (viewdata.model != null) { value = viewdata.model datetime?; } bool? datepicker = viewdata["datepicker"] nullable<bool> ?? true; bool? timepicker = viewdata["timepicker"] nullable<bool> ?? false; bool? showformat = viewdata["showformat"] nullable<bool> ?? true; bool? small = viewdata["small"] nullable<bool> ?? false; string groupclass = small.value ? "input-group input-group-sm" : "input-group"; idictionary<string, object> htmlattributes = viewdata["htmlattributes"] == null ? new dictionary<string, object>() : viewdata["htmlattributes"].todictionary(); string inputname = htmlattributes.containskey("name") ? htmlattributes["name"].tostring() : html.nameformodel().tostring(); string ngmodel; if (!htmlattributes.containskey("ng-model")) { ngmodel = "model." + inputname; htmlattributes.set("ng-model", ngmodel); } else { ngmodel = htmlattributes["ng-model"] string; } htmlattributes.set("name", inputname); htmlattributes.set("id", html.idformodel()); htmlattributes.set("class", "form-control"); //htmlattributes.set("ng-init", ngmodel + " = ((" + ngmodel + " == '0001-01-01t00:00:00' || " + ngmodel +" == '1/01/0001 12:00:00 am') ? '' : " + ngmodel + ")"); // hack: make datetime.minvalue display empty htmlattributes.set("date-time-picker", string.empty); const string date_format = "dd/mm/yyyy"; const string date_format_hint = "dd/mm/yyyy"; const string time_format = "hh:mm a"; const string time_format_hint = "h:mm am/pm"; string datetimeformathint; string datetimeformat; if (datepicker == true && timepicker == false) { //datetimeformat = "d/m/y"; // xdan datetimeformat = date_format; datetimeformathint = date_format_hint; htmlattributes.set("default-time", "00:00:00"); // set default time start of day } else if (datepicker == false && timepicker == true) { //datetimeformat = "g:i a"; // xdan datetimeformat = time_format; datetimeformathint = time_format_hint; } else { datetimeformat = "d/m/y g:i a"; // xdan // datetimeformat = date_format + " " + time_format; datetimeformathint = date_format_hint + " " + time_format_hint; } htmlattributes.set("format", datetimeformat); //htmlattributes.set("placeholder", datetimeformathint); if (datepicker == true) { htmlattributes.set("use-datepicker", "true", true); } if (timepicker == true) { htmlattributes.set("use-timepicker", "true", true); } } <div class="datepicker"> @html.textboxfor(m => m, htmlattributes) </div> @if (showformat == true) { <div class="help-block small">eg: @datetimeformathint</div> }
i think problem timeformat don't know how fix it. because if comment following line out
htmlattributes.set("format", datetimeformat);
the date value appears both in ie9 , ie 10 brings problem date gets displayed :
2015-09-22t14:00:00+10:00
fix
setting format in editor template dd/mm/yyyy h:mm
thank suggestions.
which version of angular js have been using? because here link compatibility https://docs.angularjs.org/guide/ie.
here link issue have been facing angular js not working ie9 works other browsers
Comments
Post a Comment