I'm looking for a solution for validating string gadgets at the point of input, if that's possible.
It is not always appropriate to validate a screenful of user inputs just prior to saving a record or processing data.
In legacy systems, which were usually driven through keyboard input, the user would press Enter after inputting a field value and the software would validate it at that point, disallowing further input progress until corrected. I know that is not possible in the same way with a GUI form, because (a) Enter isn't normally used and (b) there are other forms of 'navigation-away' from the input, such as clicking on another field.
I read an article about C# Windows forms validation, which gives the below synopsis. Is there a mechanism in PureBasic that allows for a similar concept?
This is a generalised question, but to the extent that sample code is helpful to serve as the basis for the requirement, I provide the below. Let's say for example that we need to validate that the group is four characters in length and the cost is between zero and 999.99. How might that be achieved?Once the user has entered a value to the control and moves the focus from the control, then the Validating event is fired. Here, I evaluate the input value according to a correct value based on the data type selected by the property DataType.
https://www.c-sharpcorner.com/UploadFil ... plication/
I'd like to know how to do this using PureBasic functions — not to have to move to some other product.
Code: Select all
win.i = OpenWindow(#PB_Any, #PB_Ignore, #PB_Ignore, 475, 210, "Test", #PB_Window_MinimizeGadget | #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
TextGadget(#PB_Any, 30, 30, 160, 25, "Item ref.")
TextGadget(#PB_Any, 30, 65, 160, 25, "Group")
TextGadget(#PB_Any, 30, 100, 160, 25, "Cost")
pcode.i = StringGadget(#PB_Any, 200, 25, 140, 25, "")
group.i = StringGadget(#PB_Any, 200, 60, 100, 25, "")
cost.i = StringGadget(#PB_Any, 200, 95, 100, 25, "")
SetActiveGadget(pcode.i)
Repeat
event = WaitWindowEvent()
; Debug "Event = " + event
Select event
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
; Debug "EventGadget() = " + EventGadget()
Select EventGadget()
EndSelect
EndSelect
ForEver
CloseWindow(win.i)
End


