Validating a Date Format with a Datepicker Field

I’ve set up a datepicker field, with a minimum date of 01/01/1920, when I’ve been testing my form I found that if I entered a completely rubbish date like this. I get a date in this year
rubbishgetsthis year

if I enter a partial date with the day/month, I get this

Only if I enter a date that has a number in the year, do I get my min date.

Here is a clone of the datepicker, you can replicate exactly what happens:

I do not have to enter a full date, or retain the format of the date that I set in the UI. of %d/%m/%Y

I put some error handling around - if the user enters a partial date like 01/9/8 then I can bring up an error code, that works fine, but how do I handle rubbish, since the datepicker is converting it into a workable date, so it doesnt bring up an error

But should the datepicker accept rubbish and convert it to a date?

It looks like you’re comparing a string to a tuple of a string in your conditional

The error handling does work, so apologies if putting that code in caused confusion (have edited and removed it).

Its more of the fact that the datepicker is converting rubbish dates into actual dates, so how can I error check that?

What distinguishes a rubbish date from a legitimate date? If you can articulate that, put it into code.

For example, if it’s that the date can’t be before the current date, you can check that. If it’s that the date can’t be more than 20 years into the future, you can check that. If it’s that the date can never be April 1st, you can check that.

There are tons of examples online about doing date and datetime comparisons in Python that can handle both of those checks and more.

All these checks are done when you’re pulling the date out of the date picker. The date picker itself just makes sure that what the user entered is in valid date format.

I’ve done the error checking on the date, so it cant be after today, but its the fact that the datepicker itself is converting
to a valid date, when its not.
But the datepicker is not returning 555555 its returning 5/4/2022, but it would be impossible to validate what the datepicker has converted it to, as it could be genuine. The only thing that can be validated on that is if the datepicker actually presented 555555 as the date, or 01/01 as the date, but it doesnt.

I have not cloned the app, but looking at the snapshot I have the feeling that you are confusing the validation of the datepicker with the validation of the textbox.

If you want to validate the datepicker, then you shouldn’t care about what the datepicker gets in input. You should only care about what the datepicker returns, which is automatically validated and constrained by the minimum date.

If you want to validate the textbox, then don’t think about the datepicker. Think about validating a textbox.

Yeah, I see what you mean now, if the user types something into the textbox the date picker is using.

Unfortunately, I think you have to trust what the date picker returns.

Edit: or, if you want the user to be able to enter dates using the text box instead of the date picker, there’s a custom component for that in the Wiki of custom components: [Wiki] Awesome custom components, dependencies (and the like)

Well I do have a secondary check, the code I have adds up all the age years returned from travellerages, then when they come to enter the traveller details they are given those (possibly incorrect) dates again. If they change them to the correct dates, and the years differ by more than 1 year from what they were quoted, they will get an error message saying go back and re-do the quote.

We also have a minimum age on the policy, at least one traveller has to be 18, so if all the dates were entered as rubbish (e.g. years would be 2022) then it would raise an error.

Its not ideal, but it does sort of work.

I will investigate your textbox option!