skip to Main Content

I am using a jQuery inputmask on the following form element (named ‘Last_Reviewed_On’) of my ASP.NET web application:

                        <div class="col-sm-4 form-floating">
                            <input type="date" class="form-control d-flex" 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.

2

Answers


  1. Chosen as BEST ANSWER

    So the answer to this was to switch to a bootstrap datepicker control, using this code:

    <div class="input-group date" data-provide="datepicker">
        <input type="text" class="form-control" 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.


  2. Quite sure for a label you use text() and not val() as you have.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search