Run plugin when field changed  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Run plugin when field changed

Postby DannyC » Fri Feb 13, 2015 5:06 pm

Hi,

I have the following plugin code which I want to fire when a field has been changed but only when it has lost focus. Currently this fires on every character entered into a field.
Code: Select all
Public Class FormPlugin
    Inherits System.MarshalByRefObject
    Implements JiwaApplication.IJiwaFormPlugin

    Public Overrides Function InitializeLifetimeService() As Object
        ' returning null here will prevent the lease manager
        ' from deleting the Object.
        Return Nothing
    End Function

    Public Sub SetupBeforeHandlers(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.SetupBeforeHandlers
    End Sub

    Public Sub Setup(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.Setup
      Dim InventoryForm As JiwaInventoryUI.InventoryMaintenanceForm = DirectCast(JiwaForm, JiwaApplication.IJiwaForm)
      AddHandler InventoryForm.Inventory.PropertyChanged, AddressOf Changed               
    End Sub
   
   Sub Changed(item As JiwaInventory.Inventory, e As System.ComponentModel.PropertyChangedEventArgs)
      messagebox.show(e.PropertyName)
   End Sub
End Class


I think the line which needs changing is
Code: Select all
      AddHandler InventoryForm.Inventory.PropertyChanged, AddressOf Changed

but I don't know the appropriate event.

I basically need it to behave the same as the old breakout Inventory Changed.

Can you assist?

Thanks

Danny
User avatar
DannyC
Senpai
Senpai
 
Posts: 635
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 29

Re: Run plugin when field changed  Topic is solved

Postby Mike.Sheen » Wed Feb 18, 2015 11:33 am

Hi Danny,

You probably want to hook into the Validated event of the textbox / control you are interested in.

Attached is a sample plugin which does this for the Part No. textbox of the inventory maintenance form.

Plugin Inventory Field Validation.xml
Sample Plugin
(31.98 KiB) Downloaded 86 times


Mike
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2440
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 755

Re: Run plugin when field changed

Postby DannyC » Wed Feb 18, 2015 1:01 pm

Mike,

Thanks for that. Two issues using the Validated.
1. It fires when losing focus whether the value has changed or not. I only want to run my code if the value has changed.
2. What I really want to do is set a custom field with a date when the Sell Price or RRP has changed.

At the moment my code looks like this but I'm getting an error dimming the InventoryForm in the Sellprice_changed sub.

Code: Select all
    Public Sub Setup(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.Setup
      Dim InventoryForm As JiwaInventoryUI.InventoryMaintenanceForm = DirectCast(JiwaForm, JiwaInventoryUI.InventoryMaintenanceForm)
      AddHandler InventoryForm.SellPriceNumericEditor.Validated, AddressOf Sellprice_Changed               
    End Sub
   
   Sub Sellprice_Changed(Sender As Object, e As System.EventArgs)
      'messagebox.show("value: '{0}'")    'This doesn't work
      Dim InventoryForm As JiwaInventory.Inventory = DirectCast(Sender, JiwaInventory.Inventory)
      InventoryForm.CustomFieldValues.ItemFromSettingName("SellChangeDate").Contents = Now.ToString()
   End Sub


Thanks
Danny
User avatar
DannyC
Senpai
Senpai
 
Posts: 635
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 29

Re: Run plugin when field changed

Postby Mike.Sheen » Sun Feb 22, 2015 2:42 pm

DannyC wrote:Mike,

Thanks for that. Two issues using the Validated.
1. It fires when losing focus whether the value has changed or not. I only want to run my code if the value has changed.
2. What I really want to do is set a custom field with a date when the Sell Price or RRP has changed.

At the moment my code looks like this but I'm getting an error dimming the InventoryForm in the Sellprice_changed sub.

Code: Select all
    Public Sub Setup(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.Setup
      Dim InventoryForm As JiwaInventoryUI.InventoryMaintenanceForm = DirectCast(JiwaForm, JiwaInventoryUI.InventoryMaintenanceForm)
      AddHandler InventoryForm.SellPriceNumericEditor.Validated, AddressOf Sellprice_Changed               
    End Sub
   
   Sub Sellprice_Changed(Sender As Object, e As System.EventArgs)
      'messagebox.show("value: '{0}'")    'This doesn't work
      Dim InventoryForm As JiwaInventory.Inventory = DirectCast(Sender, JiwaInventory.Inventory)
      InventoryForm.CustomFieldValues.ItemFromSettingName("SellChangeDate").Contents = Now.ToString()
   End Sub


Thanks
Danny


Hi Danny,

Ok - you really should get the price at read end of the business logic, and then at save starting compare the two and then set your custom field value. Relying on user interface events isn't reliable - as there are many ways the user can set the sell price (sell price text box, or the pricing grid on the prices tab).

Attached is a plugin which works for me.

Plugin Inventory Maintenance - Log date sell price changed by user.xml
Sample plugin
(32.82 KiB) Downloaded 96 times


Mike
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2440
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 755


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 3 guests

cron