Article Preview
Buy Now
FEATURE
TextField Warning
Indicating invalid entries with a warning sign
Issue: 17.4 (July/August 2019)
Author: Markus Winter
Author Bio: Markus is a Molecular Biologist who taught himself REALbasic programming in 2003 to let the computer deal with some exceedingly tedious lab tasks. Some call it lazy, he thinks it smart. He still thinks of himself as an advanced beginner at best.
Article Description: No description available.
Article Length (in bytes): 6,881
Starting Page Number: 24
Article Number: 17403
Resource File(s):
project174003.zip Updated: 2019-06-30 18:21:42
Related Link(s): None
Excerpt of article text...
For my
NumbersOnlyField
articles I find myself in need of a TextField that flags when an entry is invalid. While it is easy enough to directly draw a warning sign on the window beside the TextField, that approach would lead to problems if the window has custom backgrounds, or the TextField is locked to the window and the window gets resized. Following that path quickly gets more complex and messy than it is worth. But Xojo provides a much easier and simpler way for us as we can use a TextField in aContainerControl
instead!So what do we want to achieve? We want a TextField that draws a warning triangle when an entry is invalid (e.g. not a number), and a checkmark or something else when it is valid.
So first we make a custom class
TextFieldWithDrawing
with superTextField
, and give it a propertyIsValidEntry as Boolean
with the default value set tofalse
(always choose the safe default option, because an empty field is not a numeric value anyway).Note that it is better to use positive Booleans like
IsValidEntry
rather than negated Booleans likeIsInvalidEntry
. Why? Because it is more difficult to follow double negations likeif IsInvalidEntry = False
orif Not IsInvalidEntry
... which is the same asif IsValidEntry = True
orif IsValidEntry
.As the TextField needs to react to input, we add an event handler for
TextChanged
, and also create an identical event definitionTextChanged
in order to be able to propagate the event.
...End of Excerpt. Please purchase the magazine to read the full article.