views:

193

answers:

4

In the very common scenario where you have a textbox, and some kind of validation rule which constraints the valid entries on that textbox. How should a failing validation affect the content of the textbox especially in the case when there originally was a valid value entered before the invalid.

Example: Imagine a form where one can enter a number between 0 and 50. The user enteres 40. Everything is fine. But then the user goes in and changes it to 59.

Obviously IMHO the application should inform him about his mistake asap. But what to do with the values? I think there should be a way back to the 40 as an easy way to a valid state, but I'm not sure when and how to revert it: On focus lost? Only on a special key/ button press?

What do you think?

Edit: I absolutely agree with the first two answers: changing the input automatically is a bad idea. Yet I would like to keep the 'last valid' value available ... Maybe a clean UnDo feature would to the trick?

+2  A: 

Depends on you functional specs really, but yeah falling back to the previous correct value sounds like a good practice ... for a blocking error which will always be blocking.

However do you really want to block your user there? What if the valid range is 0-50 when option b is selected but becomes 0-60 when option c is selected? And the user decides to change the ranged value first? Then the user will be very frustrated at having lost what she considers a perfectly valid value...

Keep that in mind when automatically reverting a change made by a user :) The user may have made a mistake but may also have made the change intentionnaly because he associated it to another change in his mind but can't change both at the same time in the application...

Warn that the value is invalid and let ctrl-Z cancel the stuff the user put there may be a more sensible default.

Jean
+12  A: 

The approach that I take to field validation like this is pretty simple:

Thou Shalt Not Discard the Users Input

If the entry made by the user is invalid, flag it as such - but don't change the value.

The reasoning behind you is simple - consistency.

Consider, for example, a pair of fields used for entry of a date range where "valid" means that the start date is before the end date.

Now, the user wants to enter a completely new range.

If your system discards invalid entries immediately, you force your user into different behaviour. For entry of an earlier date range, the start date must be entered first; for entry of a later date range, the final date must be entered first. Unfriendly.

Instead, respect the users input - when the start date is entered, freely flag it as invalid, but leave the value in place. Then, when the final date is entered, both fields now validate.

This is also motivation for displaying validation dynamically (as values are changed), but for not limiting the users movement between fields.

Bevan
Yeah, its really annoying when applications change values for you. You provided a good example. Another one: imagine if autocompletes selected the first value when you pressed <esc> instead of <enter>.
Richard Levasseur
Thou art righteous
DrG
+2  A: 

@Bevan Thou art righteous.

If you want to see an example of how annoying it can be crack open Google Analytics

This unfriendly behaviour is exactly what Google Analytics does when you try to compare dates, and it drives me crazy.

If you enter an end date which is before your start date, it discards your entry and thus forces you to enter information in a prescribed sequence.

It also means that small typo's can mean you being forced to retype a whole date, which just sucks.

DrG
+1  A: 

I agree with the other answers in not changing the user input, you cannot tell what about it may be wrong, perhaps it was a typo, an missing decimal, swapped day/month/year fields, etc. An undo option to allow them to revert back to previous might be an added nice feature however.

The main items in my view are: - make it clear what the valid ranges and formats are BEFORE the user enteres the data in the form, via examples or other similar indicators. - be sure to indicate mandatory fields clearly prior to submision. - user controls that limit the user to entering valida data - date pickers, spin controls, numeric only controls, max lengths set on textboxes, etc. - make it clear when validation fails as to what item(s) on the form are invalid and why they are invalid, not just a simple "data is incorrect" global message, espeically if you have a long form with many fields that could have validation issues.

schooner