{Solved} Typing in character t automatically inserting current datetime in datepicker controls on WebForms in Dynamics 365/ PowerApps Portals

Well, this one is indeed weird when I first time saw it. So basically we set up custom datetime format in portals to dd-MMM-yyyy.

If you are unware of custom datetime format in portals, you can follow this blog here.

All set and done, I launch a webform and the first step of the webform is the account details page. I have field “New Date Field” on the form. Remember the format of datetime in portal is dd-MMM-yyyy.

In line with the format, I try to key in the date – 12-Oct-2020. And observe the behavior.

As you can see from the above experience, the moment in keyed in “t”, it printed the new date. Trust me this is one of the hardest bugs to catch and if I would not have faced this one, I could never know about it.

What is our way out here? Well, I am a developer by heart and whenever something like this comes up, I try to dig in to the root cause of it.

The first thing I wanted to check if there is any keydown handlers attached when I press the key ‘t’. To find that, I tried the below code

image

Here “cr6d3_newdatefield” is my date field logical name in CRM. So you can see there is a keydown event handler and using the developer tools I went inside that function

As you can see from the below screenshot, there is a function attached on keydown of character ‘t’ which sets the value to current datetime.

image

Awesome isn’t it, to find these little little things. So exploration is done. Now what is the next step? How to make it work.

Well the easiest option I found was to remove the keydown event altogether.

$(“#<yourdatefield>_datepicker_description”).data(“events”)[“keydown”][0].handler = null;

Well, not the most elegant but certainly it works.

Hope this helps!

Debajit Dutta

(Dynamics MVP)

For consultation/ corporate training visit www.xrmforyou.com or reach out to us at info@xrmforyou.com

Our product offerings:

CRM-Sharepoint Attachment uploader and metadata manager (http://www.xrmforyou.com/sharepoint-integrator.html)

Notes Manager (https://debajmecrm.com/add-metadata-to-your-notes-and-attachments-in-dynamics-notes-metadata-manager-from-xrmforyou-com/)

Role based views for Dynamics 365 (http://www.xrmforyou.com/role-based-views.html)

Record Cloner for Dynamics 365 (http://www.xrmforyou.com/record-cloner.html)




Discover more from Debajit's Power Apps & Dynamics 365 Blog

Subscribe to get the latest posts sent to your email.

Discover more from Debajit's Power Apps & Dynamics 365 Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading