The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
|
|
Best way to perform field validation?
Posted: 05 Oct 09 11:16 AM
|
Take System:Account Detail, for example. If I want to ensure that a CustomerID field is entered only once in SalesLogix, how is this best handled? I've tried the OnExitControl event but that doesn't seem to work right. Here's the code:
Sub txtCustomerIDExitControl(Sender) If "" & txtCustomerID.Text <> "" Then If "" & GetField("C_TW_CustomerID", "Account", "C_TW_CustomerID = '" & txtCustomerID.Text & "'") <> "" Then txtCustomerID.Text = "" frmAccountDetail.Post MsgBox "This CustomerID already exists for another account.", vbOKOnly, "CustomerID Not Unique" End If End If End Sub
This works okay if the user happens to click into another field. But if they change the CustomerID and then navigate to the next account, duplicate data can be saved. OnChange doesn't work for this either. So, how is this best handled? I appreciate your comments! |
|
|
|
Re: Best way to perform field validation?
Posted: 07 Oct 09 4:18 PM
|
have posted these ONExit bugs several times.....including 7.5.2 beta 3.
Try capturing Escape, Enter Keys....handling clicking repeatedly into the same control (each click fires off the on exit!) or as you've seen if they navigate away from the form sometimes SLX doesn't even catch the OnExit.....add in Formatted data (currency, phone number) and it really becomes tricky.
Here's what we do..... 1. put a dummy "Save CustomerID" button next to the ID field. Invisible 2. When they enter the CustomerID field, make the Save CustomerID Button VISIBLE. 3. When they click on the Save CustomerID button, simply make this button invisible.
Basically you've forced them to click on the form after editing the customerID field, and the OnExit will fire off. If they navigate away from the form and the CustomerID doesn't save, you ask them if they clicked on the Save button before they left their changes stranded in Never Never Land!
We've used a Green S button, a Blue diskette icon, etc. (and a Red button with a big black X on it for Delete/clear out.
|
|
|
|
Re: Best way to perform field validation?
Posted: 07 Oct 09 4:54 PM
|
Have you tried the "OnValidate" event of the Form?
Not sure how much 7.5.2 has changed from 7.5.1, but if you look at the Account Detail form, it may already have a handler for the OnValidate event of the Form. It is on this Event where you could check the value of the field and prevent the user from going away from this record (or from Saving) by returning "False"
E.g. Function AXFormValidate(Sender) If Not MyCustomValidationFunction() Then 'Issue Error Message (could be done inside the validation function) 'Set Focus to Field (could be done inside the validation function) AXFormValidate = False End If End Function |
|
|
|
Re: Best way to perform field validation?
Posted: 08 Oct 09 2:55 PM
|
I appreciate the feedback. AXFormValidate seemed to do the trick. If duplicated, I was unable to navigate to a different record, save the change, or close the main view. I think that covers all scenarios. Thanks for the suggestion! |
|
|
|
Re: Best way to perform field validation?
Posted: 08 Oct 09 3:00 PM
|
Glad to hear that the event is still there and functions properly, since as stated, I have built many customizations in the past that depend on it.
|
|
|
|
Re: Best way to perform field validation?
Posted: 09 Oct 09 9:23 AM
|
I was having the same issues, and I put my code in the AXFormValidate as well, but I am getting errors when I enter bad data and then just click onto another function such as Contact or Reports on the left nav bar. I get and error calling method AXFormValidate : "Cannot focus a disabled or invisible window". If I then exit out of SLX, the bad data is saved. |
|
|
| |
|
Re: Best way to perform field validation?
Posted: 22 Jun 10 8:31 AM
|
Just to confirm that an error\defect has been raised with SalesLogix concerning using the OnExit event of a control when the control is IN a panel. The onexit event fires TWICE when the control is in a panel, once when the control is on a form (or floating over a panel but not 'grouped' IN the panel).
We were getting false firings when the user clicked into a calculation field (Price * Quantity = Amount kinds of stuff) and then mouse clicked into the same field.
This has nothing to do with AXFormValidate which Raul pointed out is a great way to handle field validations prior to closing down a form. |
|
|
|
Re: Best way to perform field validation?
Posted: 28 Sep 10 10:46 AM
|
Originally posted by Bailey1
I was having the same issues, and I put my code in the AXFormValidate as well, but I am getting errors when I enter bad data and then just click onto another function such as Contact or Reports on the left nav bar. I get and error calling method AXFormValidate : "Cannot focus a disabled or invisible window". If I then exit out of SLX, the bad data is saved. |
|
|
|
|
|
Re: Best way to perform field validation?
Posted: 28 Sep 10 10:46 AM
|
Originally posted by Bailey1
I was having the same issues, and I put my code in the AXFormValidate as well, but I am getting errors when I enter bad data and then just click onto another function such as Contact or Reports on the left nav bar. I get and error calling method AXFormValidate : "Cannot focus a disabled or invisible window". If I then exit out of SLX, the bad data is saved. |
|
Has anyone found a solution to this problem? |
|
|
|
Re: Best way to perform field validation?
Posted: 28 Sep 10 10:47 AM
|
Originally posted by Bailey1
I was having the same issues, and I put my code in the AXFormValidate as well, but I am getting errors when I enter bad data and then just click onto another function such as Contact or Reports on the left nav bar. I get and error calling method AXFormValidate : "Cannot focus a disabled or invisible window". If I then exit out of SLX, the bad data is saved. |
|
Has anyone found a solution to this problem? |
|
|
|