locked
Validating input to a textBox in a settings panel

    Question

  • In a C# Windows 8 app, I have a settings panel with, among other things, a textBox.  The expected input is a number within a certain range.  What is the proper way to validate and respond to an invalid input?

    Validate when the textBox loses focus?

    On an invalid input, block the app with a message dialog or a non-blocking error message in the panel?

    Leave the user's incorrect input in the box or replace it with some default but legal value or a blank value while returning focus to the textBox?

    Or other?

    Thursday, August 30, 2012 2:46 PM

Answers

  • I would validate when the text box changes and report the error with an in-line non-blocking error. If you have partial input which is inherently invalid then you can filter that out, but I wouldn't alter input which is currently invalid but which could become valid either by further typing or by changing a different option.

    I prefer leaving invalid input for the user to change rather than forcing it to a default or blank value: as a user it frustrates me when I partially enter a value, switch away to confirm that what I have is correct, and then come back and my edits have been lost.

    If the user exits the setting pane with an invalid setting I'd cancel the change and leave the setting where it had been previously.

    See the Errors section in the Laying out your UI docs for an overview of best practices for reporting errors.

    --Rob

    • Marked as answer by jrboddie Thursday, August 30, 2012 4:51 PM
    Thursday, August 30, 2012 3:47 PM
    Owner

All replies

  • here is a guideline about how to implement error messages and when what technique to use:

    http://msdn.microsoft.com/en-us/library/windows/apps/xaml/Hh465330(v=win.10).aspx

    Thursday, August 30, 2012 3:23 PM
  • I would validate when the text box changes and report the error with an in-line non-blocking error. If you have partial input which is inherently invalid then you can filter that out, but I wouldn't alter input which is currently invalid but which could become valid either by further typing or by changing a different option.

    I prefer leaving invalid input for the user to change rather than forcing it to a default or blank value: as a user it frustrates me when I partially enter a value, switch away to confirm that what I have is correct, and then come back and my edits have been lost.

    If the user exits the setting pane with an invalid setting I'd cancel the change and leave the setting where it had been previously.

    See the Errors section in the Laying out your UI docs for an overview of best practices for reporting errors.

    --Rob

    • Marked as answer by jrboddie Thursday, August 30, 2012 4:51 PM
    Thursday, August 30, 2012 3:47 PM
    Owner