Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Multiple Textboxes with Valid Code
Message
From
18/04/2021 20:57:11
 
 
To
18/04/2021 09:03:07
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01679876
Message ID:
01679886
Views:
46
>I have about 5 text boxes on a form. When the form pulls up the setfocus is on text box 1. I have validation code that checks to see if the textbox is empty, if it is, it changes tHE background color to red etc. When I pull up the form and goto the next page (w/o clicking any textboxes but the focus is on the first textbbox), the background is ONLY changed ffor the first text box (which is correct), but I would expect ALL textboxes that failed validation to had red box (even if I dont click on the text box).

You've had a few seemingly related threads lately. I'm not sure of your coding strategy but I'm guessing you might be using validation code attached to the controls themselves (?)

What I usually do in scenarios like this is create a method, something like .AreTextBoxesOK( ) attached to the container which holds all the textboxes. This method tests all the textboxes, changes colours etc.

Then, each textbox has something like this in its .Valid():
=This.Parent.AreTextBoxesOK()
RETURN .T.
* so the user can go to the next field if they want, even if there's an issue with the current textbox value
Users can press Enter to leave a textbox when they're finished editing, or press Tab, or use the mouse. Rather than try to trap all those events individually I just call a parent method such as above when a user has made changes, .Valid() usually works well for that.

If you return a logical value from .AreTextBoxesOK( ) you can use that as part of form validation i.e. don't allow saving if there's a data entry issue. You can also add conveniences such as setting the focus to the first textbox which has an error, if there is one.
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Previous
Reply
Map
View

Click here to load this message in the networking platform