Community
Showing results for 
Search instead for 
Do you mean 
Reply

Validate Field

Tuned Listener
Posts: 10
Country: Brazil

Validate Field

Hi,

I´m writing my second plugin (for ACT 2007).
The first one worked fine, I was able to run, debug, etc.

Now I need to write a plugin that must validate a specific text field when the user gets out of the field.
From the SDK samples I'm using the code below, with the insertion of the AddHandler for the sub Actapp_FieldLeave,
but the sub is never fired.
Is this the correct way to do this job ? Is there another way to do that ?

Thanks in advance



Imports System
Imports System.Windows.Forms
Imports Act.Framework.Contacts
Imports Act.Framework.Histories
Imports Act.UI


Public Class Class1
Implements IPlugin

Public Sub New()

End Sub

Public Sub OnLoad(ByVal App As ActApplication) Implements IPlugin.OnLoad
ActApp = App 'Store a reference to ActApplication
AddHandler ActApp.AfterLogon, AddressOf ActApp_AfterLogon
AddHandler ActApp.BeforeLogoff, AddressOf ActApp_BeforeLogoff
AddHandler ActApp.Leave, AddressOf Actapp_FieldLeave
End Sub 'OnLoad


'---------------------------------------------------------------------------------

Private Sub Actapp_FieldLeave(ByVal Sender As Object, ByVal e As System.EventArgs)
'This code was expected to fire when the user clicks outside a field
End Sub
'---------------------------------------------------------------------------------


Private Sub ActApp_AfterLogon(ByVal Sender As Object, ByVal e As System.EventArgs)
'This code is fired as expected
End Sub

Private Sub ActApp_BeforeLogoff(ByVal Sender As Object, ByVal e As System.EventArgs)
'This code is fired as expected
End Sub

End Class
Copper Contributor
Posts: 98
Country: United States

Re: Validate Field

[ Edited ]
Try 'signing up' for a CurrentContactChanged event ...
which traps a FieldChanged event ...
which then handles which field has changed.
 
I know this works.
 
Code:
 private void AfterLogon(object Sender, System.EventArgs e)
 {
            try
            {
                //events
                AddMenuItem("act-ui://com.act/application/menu/tools/Test", "Trap", new Act.UI.CommandHandler(this.Test01));
                ActApp.ActFramework.Database.BeforeDatabaseLock += new Act.Framework.Database.DatabaseLockHandler(this.BeforeDatabaseLock);
                ActApp.CurrentContactChanged += new EventHandler(ActApp_CurrentContactChanged);
                
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
   
 }

        void ActApp_CurrentContactChanged(object sender, EventArgs e)
        {
            ActApp.ApplicationState.CurrentContact.Fields.FieldChanged += 
                   new Act.Framework.MutableEntities.MutableEntity.FieldCollection.FieldChangedHandler(Fields_FieldChanged);
        }

        void Fields_FieldChanged(string fieldName)
        {
            switch (fieldName)
            {
                case "TBL_CONTACT.EXAMPLE":  
     ///ETC....

 


Sorry for the C#

Message Edited by Carlton_Jones on 04-04-2008 05:03 PM
Carlton Jones
Sage Software
Tuned Listener
Posts: 10
Country: Brazil

Re: Validate Field

Thanks a lot for your answer. That's worked, but actualy is not exactly what I need. The CurrentContactChanged fires at every character typed, but I must check the field only when the user is finished typing data. Any other idea ?
Bronze Elite Contributor
Posts: 2,115
Country: United_Kingdom

Re: Validate Field

Hiya,

 

Maybe you could use the Act.MutatableEntities.MutatableEntity.Update Event? Act.Framework.Contact inherits from MutatableEntity. I think the Update event is fired when the Contact is commited to the dB so this would be after the Save is accepted fro the Contact.

 

HTH

Vivek

Vivek Gargav
Caldere Associates Ltd.
www.caldere.com
vgargav@caldere.com
My Blog