I have this field, EXP_DEL_DATE, which is defined in a class as follows :
[BindProperty]
[Required(ErrorMessageResourceType = typeof(MsgsResource), ErrorMessageResourceName = MandatoryFld)]
[JsonPropertyName("expDelDate")]
[Display(Name = nameof(CommonResource.ExpDelDate), ResourceType = typeof(CommonResource))]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd-MM-yyyy}", ApplyFormatInEditMode = true)]
public DateOnly EXP_DEL_DATE { get; set; }
It is bind to a date picker (flatpickr) in a .cshtml page using a TagHelper.
<div class="col-md-4">
@Html.LabelWithMandateFor(m => m.WOHeader.EXP_DEL_DATE)
@Html.TextBoxFor(m => m.WOHeader.EXP_DEL_DATE, "{0:dd-MM-yyyy}", new { @class = "form-control flatpickr flatpickr-input " + woInfo, type = "date", data_provider = "flatpickr" }).DisableIf(() => !Model.FLD_STATUS.REQ_DEL_DATE_OK)
<span class="invalid-feedback" asp-validation-for="WOHeader.EXP_DEL_DATE"></span>
</div>
When this form is submitted to server via Ajax, I encountered the following:
Using Chrome/Edge/Firefox (Windows): this field is mapped correctly into the object class.
Using Safari in MacOS: this field has failed the data annotation validation check saying it is not a valid date format even though it has the same value of "dd-MM-yyyy" as item 1.
I have the following localization options configured in program.cs.
builder.Services.Configure<RequestLocalizationOptions>(options =>
{
var culture = CultureInfo.CreateSpecificCulture("en-US");
var dateformat = new DateTimeFormatInfo
{
ShortDatePattern = constDTFormat_ddMMyyyy,
LongDatePattern = constDTFormat_ddMMMyy_Hmmss
};
culture.DateTimeFormat = dateformat;
var supportedCultures = new[]
{
culture
};
options.SupportedCultures = supportedCultures;
options.SupportedUICultures = supportedCultures;
options.DefaultRequestCulture = new RequestCulture("en-US", "en-US");
});
I read something saying the browsers may override app's date format. Any advice on how to tackle this issue?