When a TextBox has invalid data, Validating event still allows the cursor to jump to the next available control and just returns back to control being validated event if the e.Cancel = true. In WinForm, the cursor stays at the control until it passes the validation logic.
Another observation that needs patience. Run the attached sample. Click on “Full Name” textbox but don’t enter anything -> Click “City” textbox for several times (don’t know how many) in quick succession. Once you get your luck, you will be able to enter data in City textbox even if FullName hasn’t passed the validation yet.
The focus and validation have had a significant overhaul in the current update. Now there is no need to attach the handlers to enable the events. You can also use the On(Event) overrides without the handlers.
There were several problems, some are:
And few others. Should all work now.
There is an ongoing issue with the validation event. The problem is that we don’t receive the focusin/out events unless the control attaches any of the validating or focus events. The fix will be to always subscribe like all the other events.
Wisej has a state map that is sent back from the client at the top of every event stream to ensure that the server is always in sync with the client, even if for whatever reason an event is missed. When you tab out and nothing changed there is nothing sent so the server doesn’t know that the focus has changed and the next validate will fail. It will be fixed in the next updating coming up tonight.
Thanks you for your patience on this. Debugging focusing events is always frustrating.
When should a textbox’s Invalid property be updated? With an empty textbox with a Validating event, the property is not updated the first I tabbed-out of the control. It’s only sets to true the second time I press tab.
the regression, logged as WJ-7451 is fixed in the latest build (1.2.31)
Thanks. The focus/blur (and related validation) broke when we added the Tools to the textbox because that required wrapping the actual input control into an outer widget. It’s fixed in dev.
Cancel the Validating event: Wisej will force (it may fail if you keep clicking due to timing issues :)) the invalid control to gain the focus back, it will automatically set the Invalid property to true and you may optionally set the InvalidMessage tooltip.
I agree with you about the request/response in a web app but in the sample I sent yesterday, I am cancelling the Validating event by setting e.Cancel to true. But still, I was able to make an entry into the next textbox even if the previous textbox hasn’t passed the validation yet. Also, I concentrated on mouse click when I sent you the test project. But now, when I tried using Tab to go from one control to another, the Validating event doesn’t always fire. I believe that it should fire everytime the textbox loses focus.
Do not cancel the Validating event. But you can set the control to Invalid and set the InvalidMessage. This is more “web-like” where the actual full validation is executed on save but you show the invalid state.
This approach will resolve the problem as cancelling the event is very restrictive to the user and this is what I follow in a real-world application and revalidate all or invalid controls before saving.
Use the ErrorProvider to display an error icon next to the invalid control, similar to the method above
The test project I sent you is using the ErrorProvider to notify the user of invalid data.
I am attaching the revised test project that shows the value of the Invalid property everytime the Validating event is fired. I also includes a DataGridView to show how CellValidating event works. The cursor always stays in CustomerID if it is invalid.
Thanks for the sample. I haven’t tried it yet.
But about the validation in general, we can’t block the cursor from changing the focus, otherwise you’d have to wait for a server request/response everytime the user tabs around. That’s why we also added the InvalidMessage and Invalid property as well as the ErrorProvider component.
Basically with Wisej you can validate in 3 different ways (this will be a new topic in the docs):