Why Making State Unrepresentable Is Wrong

I have been working with some validation code for a UI.
One of the entry fields is a year so I added a range constraint to enforce a minimum.
For purposes of this example assume it is a year of birth.
Given that the oldest person alive is 118 it is fairly safe to assume that all dates of birth will be in the last 130 years.

Given that it is now 2022 this means that the value needs to be in the range 1892-2022.
Enforce this too strictly and if you enter 0 and tab away the field defaults to 1892.
This now becomes hard to edit as each time you change a digit the validation will restore the minimum value making this field really hard to edit. All you can do to make this easier is to warn that it is out of range.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s