I am using a jQuery inputmask on the following form element (named 'Last_Reviewed_On') of my ASP.NET web application:
<div >
<input type="date" id="Last_Reviewed_On" name="Last_Reviewed_On">
<label for="Last_Reviewed_On">Last Reviewed</label>
</div>
The initialization of the inputmask in my Javascript is as follows:
$('#Last_Reviewed_On').inputmask({ alias: "datetime", inputFormat: "dd/mm/yyyy" });
So, the form element works very well. It shows a 'mm/dd/yyyy' mask, and there's a calendar icon for the user to select a date as well. I can fetch the value entered by the user correctly. The problem is when I try to set the value of the form element using data from an existing record. I am using an $.ajax
call to a webhandler to fetch a record, which I then wish to display in the form. I am using the following code to populate the 'Last_Reviewed_On' form element:
$('#Last_Reviewed_On').val(data.Last_Reviewed_On);
Nothing appears in the form element though. All I see is the input mask. I know the data is there, since I used console.log
to inspect the value.
Any idea why this isn't working? I use inputmask for other fields without issue, so I'm stumped on this one.
CodePudding user response:
Quite sure for a label you use text() and not val() as you have.
CodePudding user response:
So the answer to this was to switch to a bootstrap datepicker control, using this code:
<div data-provide="datepicker">
<input type="text" id="Last_Reviewed_On" name="Last_Reviewed_On" />
<label for="Last_Reviewed_On">Last Reviewed On</label>
</div>
and the following jQuery to initialize:
$('.input-group.date').datepicker({
autoclose: true,
todayHighlight: true,
format: "mm/dd/yyyy"
});
It works well and prevents entry of invalid dates.