Datepicker in a User Custom field

The up-to-date code for the profile page is:

<script type="text/discourse-plugin" version="1.4.0">
    api.onPageChange((url) =>{
        if (url.match(/\/preferences\/profile/)) {
            var userField = document.querySelector('.user-field-test-selector');
            
            if (userField) {
                var input = userField.querySelector('input');
                if (input) {
                    input.classList.add('testSelector');
                    input.type = 'date'; // Using native HTML5 date input
                }
            }
        }
    });
</script>

Replace user-field-test-selector by the corresponding class name:


input.classList.add('testSelector'); is optional and to be added only if you need it for further modifications, I think.

Another script should be made for the account creation modal.