Datepicker min max refactor

Add validation to the input associated with the datepicker-popup.  Cleaned up some code formatting and eliminated some duplicate code.

Fixes: #1688