Search code examples
validationumbraco

Umbraco DateTime Picker Custom Validation


Have noticed that umbraco datepicker property doesn't allow for dates before 1900. Is there someway I can customize the validation to allow for this?

enter image description here


Solution

  • The minDate in the bootstrap date time picker is set to 1900. You can override this by setting the following variable (in this example I'm setting it to 1800):

    $.fn.datetimepicker.defaults.minDate = moment({y: 1800});
    

    You COULD change this in the source JS for Umbraco, but you'd lose the change if you updated Umbraco at any point. Your best bet is to add it as a script, and include it in your back offices pages using a package manifest in the app_plugins folder, something like this:

    {
        "javascript" : [
            '~/App_Plugins/YourFolder/yourfile.js'
        ]
    }
    

    Where your file sets the variable.

    There is some more information on this issue here: https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/69475-date-picker-for-pre-1900-dates