locked
when I bring the cursor over datetime input text the existing date value will be disappeard from the input text RRS feed

  • Question

  • User-1355965324 posted

    Hi

    After setting the value of Expiry date and PenaltyExpDt to the corresponding input text, and after when I place the cursor over  there, the value would be disappeared from the textbox. Why that date is no longer stay when I put the cursor over the textbox of  datetime

    LicenseModel
    public int DocCatID { get; set; }
    public DateTime? ExpiryDate { get; set; }
    public DateTime? PenaltyExpDt { get; set; }
    NotMapped]
    public string PenaltyExpDttxt { get; set; }
    [NotMapped]
    public string ExpiryDateTxt { get; set; }

    Html

    <div class="form-group">
           <label asp-for="DocCatID" class="control-label control-label-left col-sm-3 text-danger">Document Category</label>
           <div class="controls col-sm-9">
               <select class="form-control" asp-for="DocCatID"
                   asp-items="@ViewBag.Category" data-role="select" onchange="SetExpiryDate"></select>
               <span asp-validation-for="DocCatID" class="text-danger">@ViewBag.ErrorMsgCategory</span>
           </div>
     </div>
    
    <div class="col-md-6">
           <div class="form-group">
             <label class="control-label control-label-left col-sm-3">Penalty Point<br />Expiry Date</label>
           <div class="controls col-sm-9">
          <div class='input-group date' id='PenaltyDatePicker'>
             <input type='text' id="txtPenaltyExpDt" asp-for="PenaltyExpDt" class="form-control disabled" />
            <span class="input-group-addon">
         <span class="glyphicon glyphicon-calendar"></span>
         </span>
     </div>
    </div>
    </div>
    </div>
    
    
    <div class="form-group">
      <label class="control-label control-label-left col-sm-3">License Expiry</label>
      <div class="controls col-sm-9">
      <div class='input-group date' id='ExpiryDatePicker'>
       <input type='text' id="txtExpiryDate" asp-for="ExpiryDate" class="form-control disabled" />
        <span class="input-group-addon">
        <span class="glyphicon glyphicon-calendar"></span>
        </span>
       </div>
    </div>
    </div>
    <script>
     $(document).ready(function () {
    $("#ExpiryDatePicker").datepicker({ format: 'dd/mm/yyyy', todayHighlight: true, autoclose: true, todayBtn: 'linked' });
    $("#PenaltyDatePicker").datepicker({ format: 'dd/mm/yyyy', todayHighlight: true, autoclose: true, todayBtn: 'linked' }); function SetExpiryDate() { var url = '@Url.Action("GetExpiryDate", "EmpDoc")'; $.post(url, $('form').serialize(), function (view) { console.log(view); $("#txtExpiryDate").val(view.expiryDateTxt); // Here I set the value of Date into textbox in dd/mm/yyyy format $("#txtPenaltyExpDt").val(view.penaltyExpDttxt);// I set the value here }); } </script>

    Controller. The corresponding Expiry Dated taking from the database and set to textbox using the function  SetExpiryDate

    public IActionResult GetExpiryDate(EmpDocumentModel data)
            {
                LicenseModel doc = new LicenseModel();
                var docmodel = _unitOfWork.DocumentRepository.GetExpirydate(data.EmployeeID, data.DocCatID);
                data.ExpiryDate = null;
                data.PenaltyExpDt = null;
    
                if (data.ExpiryDate != null)
                {
                    data.ExpiryDateTxt = String.Format("{0:dd/MM/yyyy}", docmodel.ExpiryDate);
                }
                if (data.PenaltyExpDt != null)
                {
                    data.PenaltyExpDttxt = String.Format("{0:dd/MM/yyyy}", docmodel.PenaltyExpDt);
                }
                return Json(data);
            }
    

    Monday, March 16, 2020 2:59 PM

Answers

  • User-474980206 posted

    I would assume its some behavior of your datepicker plugin.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 16, 2020 3:58 PM