Datepicker: Added extra checks and renamed an event to prevent the JS errors (partially fixes #4135)