Hi All,
I'm returning to B4J after a number of years of doing other things (not coding) and thoroughly enjoying it with one exception, the FocusChanged event.
I'm writing a fairly standard style of desktop app that stores data in a SQLite database and is presented in a number of forms using textfields, comboboxes, etc. Nothing fancy. And yes... I'm using the standard B4J views, not the B4X ones (call me dinosaur).
My issue is this... I fetch a row from the database and populate three textviews on the form, which also has a 'Save' and 'Cancel' button. I want each field to be validated if the User presses Enter (Action) or tabs to another field (FocusChanged). If, however, validation of the field fails I want to show an error message (fx.MsgBox) and keep focus on the Invalid field.
This is not an issue with the Action event, obviously. The problem comes with FocusChanged... If you tab off (FocusChanged lost) a field and validation fails then a MsgBox is displayed but Clicking OK to dismiss it causes a FocusChanged event as well and trying to set the focus back to the invalid field starts to become unmanageable.
Similarly, if 'Cancel' is pressed and the field is invalid, I don't want to display the MsgBox error because the form is closed and we're not saving the record.
If 'Save' is pressed then I want to show the MsgBox error and return focus to the invalid field.
Does anybody have a remedy for this... like swallowing/cancelling subsequent (unwanted) FocusChanged events or some other UI error navigation management pattern?
Update: But in the meantime I have preserved my sanity by changing the app so that if a field fails validation the msgbox is displayed and the border colour is changed to red and NOT attempting to alter the focus programmatically.
I'd still like to know if anyone has a solution for diverting focus without causing unintentional FocusChanged events...