I want to show date in dd/mm/yyyy format but it always shows mm/dd/yyyy format. Also I want to set a default date to my control on page load
My view has:
<div class="col-md-4 col-sm-4 ">
@(Html.Infragistics().DatePicker()
.ID("TDate")
.ButtonType(TextEditorButtonType.DropDown)
.Render())
<input type="hidden" value="@ViewBag.TDate" id="hdnFlag" name="hdnFlag" />
</div>
My controller has :
public ActionResult Index()
{
ViewBag.TDate = "16-MAR-2017";
return View();
}
My javascript to set the default value is:
$(document).ready(function () {
var h1 = document.getElementById('hdnFlag');
if (h1 != null) {
h1 = h1.value.replace("-", " ");
h1 = h1.split("-").join(" ");
var twd = new Date(h1);
twd.toLocaleDateString("en-GB");
var d = twd.getDate();
var m = twd.getMonth();
var y = twd.getFullYear();
$("#TDate").igDatePicker({
value: new Date(y, m, d),
dateDisplayFormat: "dd/MM/yyyy",
minValue: new Date(y - 1, m, d)
})
});
I am not able to set the date correctly also if I change the date it shows in mm/dd/yyyy format.
Can anyone please help?
Regards
Singh
Hi Aexander,
I will send you one soon.
I also want to highlight the datepicker if a different date is chosen instead of the current date. So I have written the below code if the text changes:
$("#TDate")[0].currentStyle.borderTopColor = "red";
This doesn't seems to work. Can you please suggest the correct syntax?
I want the whole border to be highlighted red and not just the top.
Hello Singh,
I have tried to reproduce the issue that you are facing but the date does not disappear when the control is hovered. I guess this behavior is caused by some custom css that you are using. Is it possible for you to provide an isolated sample that reproduces this issue so that we would be able to investigate it?
Best regards, Alexander Marinov,Infragistics
Hi Marina,
Thanks for your reply.
It works now but when I hover over the date in the control the date disappears when I move my mouse away it comes back.
Is it some in-built style? Can I change it to always show it regardless of hover?
You only need to initialize the editor once. If you initialize it a second time, you will overwrite the set options. If you want to apply option on runtime, you need to set it as shown in our online API https://www.igniteui.com/help/api/2017.1/ui.igdatepicker#options:minValue
I have isolated your case in a basic sample (look at the Home/index.cshtml file) in order to show you how to do this.
Best Regards, Marina Stoyanova, Software Developer, Infragistics, Inc.
Hi,
I am doing this because I want to set the default date to the control and I am getting this date(16-MAR-2017 OR 16/03/2017) from the DB therefore I have set that date in the controller to the Viewbag. I want to set the minimum date to be only 1 year back of the above DB date so that the user cannot choose a date which is more than 1 year old therefore I need to break the date so that I can pass it as:
minValue : new Date(y -1 , m, d)
I am attaching my sample solution. Can you please have a look a suggest. I have tried to set .dateInputFormat as you suggested but that didn't help much.