Initially I thought this to be a trivial task, but all the solutions I came up with have severe drawbacks.

The application I write is connected to machinery and all the inputs are evaluated as soon as a new value is entered. As soon as a checkbox or radiobutton is changed, the changes are immediately applied. There is no "OK" or "Submit" button, so everything has to be handled on the fly. Numeric inputs are done with spinboxes, and as soon as the value is changed, it is immediately applied. There are many such spinboxes for numerical values.

However, now I need a numeric input from 0 to about 200, but only values divisible by 5 are valid. I can set the step size of the spinbox to 5, and all works fine if the user scrolls with the mouse or presses the up or down buttons. However, once I use the keyboard, I can enter, for example, 12, and then if I spin up it will become 17. Of course, internally, the value used by the machinery was 10 and it changed to 15, but the user would see 12 and then 17.

One solution is to correct the input every time it was changed. But then the user cannot input the value 25 with the keyboard, because as soon as we type "2" it instantly becomes zero.

The other solution is to correct the input only when editing is finished. The UI elements do have the onEditingFinished() signal, but then a user could enter for example "12", and not do anything for a while, and the number displayed on the screen is "12" while the device works happily with "10". Only when other UI elements are selected, will the number jump from 12 to 10, possibly causing confusion.

Other alternatives have the problem of breaking design. There are many other number fields, so making this one completely different is not a nice solution. Using a slider or a combobox would be a last-ditch solution, but the input space is too big, 40 items in a combobox or other scrolling list can be frustrating.

Are there other alternatives which might have slipped my mind? How is such a thing commonly solved? I thought it is something very common, but now I can't find any examples of it in use.

  • 1
    I would strongly advice against auto-correction. A sudden change of the value that a user has just put in is an annoyance or even disrespectful to the user. Show an error message with the suggested value and allow the user to accept the suggestion as the new value, or leave it to the user to correct the value manually. A less obtrusive pattern like a tooltip can be used for this if that is a concern.
    – jazZRo
    Jan 10 at 17:01

1 Answer 1


There are input fields out there on the internet which validate immediately and show a message in a little box below the input field.

When entering an email address, for example, you enter "J" and get the validation message "A valid email is [email protected]". You can enter more characters, and the message stays with you until "[email protected]", when it goes away (assuming it does not know all legal top-level domains). You can add the missing "om" and if you like and submit.

Applied to your case, show the validation message "Number must be divisible by 5" as long as it isn't, show a red frame around the input field indicating this number is not currently acceptable and used by the machinery.

I am a little worried about the environment, though. If I want to turn a "50" to a "55", I must type "5" first, and the machinery, for a second until I type the second "5", runs with a completely different number. Sudden large changes like this might not be healthy for the machinery nor for the quality of the result.

  • one possible solution for your concern about the machinery is to require the user to enter 3-digit numbers (since the input goes from 0-200) so the machine would only move once the 3rd digit is entered and the input is valid.
    – Luciano
    Jan 11 at 15:20
  • You could also grey-out a "submit" button if the input is not valid, and not make changes until submitted. A "515" use case would show valid with "5", invalid at "51" and valid again at "515".
    – Dave X
    Jan 12 at 21:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.