Changing Field Value Is Not Triggering Changed Event

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
jyoung
Posts: 694
Joined: Thu Jan 21, 2016 6:43 am
Location: Oklahoma City, OK USA

Changing Field Value Is Not Triggering Changed Event

Post by jyoung »

I have a field that uses a prompter popup panel to allow a user to lookup a value. When a value is selected I set the field to the value. The problem is that the change event does not seem to be firing so the save button never gets enabled.

Here is the field and popup selection

Code: Select all

evtroutine handling(#CMDBC.PrompterActivate)
#DUNSPopup.Load( #wk_CountryCode )
#DUNSPopup.ShowPopup context(#CMDBC) placement(Center)
endroutine

evtroutine handling(#DUNSPopup.Selected) code(#code) description(#description)
#CMDBC := #code
#CMDBC.Modified := True
#DUNSPopup.ClosePopup
endroutine
The list of panel fields

Code: Select all

define_com class(#PRIM_KCOL<#PRIM_EVP #STD_STRNG>) name(#PanelFields) style(Collection)
That is populated by

Code: Select all

mthroutine name(CollectEditableControls)
define_map for(*INPUT) class(#PRIM_PCOL<#PRIM_CTRL>) name(#controls) pass(*BY_REFERENCE)

define_com class(#PRIM_EVP) name(#tempField) reference(*DYNAMIC)
define_com class(#PRIM_CPST) name(#tempContainer) reference(*DYNAMIC)

for each(#control) in(#controls)
if_ref com(#control) is(*INSTANCE_OF #PRIM_EVP)
#tempField <= #control *As #PRIM_EVP
#avFrameworkManager.avRecordTraceAValue event("Adding Control To Panel Fields") component(#COM_OWNER) avalue(#tempField.Name)

#PanelFields<#tempField.Name> <= #tempField

else
if_ref com(#control) is(*INSTANCE_OF #PRIM_CPST)
#tempContainer <= #control *As #PRIM_CPST
#COM_OWNER.CollectEditableControls( #tempContainer.ComponentControls )
endif
endif
endfor
endroutine
The field is in the collection and I listen for the changed event to enable to save button.

Code: Select all

evtroutine handling(#PanelFields<>.Changed)
#SaveButton.Enabled := True
#SaveCredit := True
endroutine
The problem is that the #PanelFields<>.Changed event is never getting invoked. I thought I remembered having to set the modified property on the field after it was changed programmaticaly because the changed event only fires when a user interacts with it.

But now, even with the Modified property set, it still does not fire. Is there anyway to get that event to fire?
User avatar
Stewart Marshall
Posts: 417
Joined: Thu Nov 05, 2015 5:25 pm

Re: Changing Field Value Is Not Triggering Changed Event

Post by Stewart Marshall »

Hi Joe

The Changed event is only fired when a value is keyed in to an edit. It does not fire when the value is changed in code.

Events aren't really meant to be used as a place to write processing, although they commonly are. Best practice is to put the processing code in a method and to call it from whatever events trigger the scenario.


You can also simplify your routine for collecting fields. If you use ComponentMembers rather than ComponentControls, you get access to all the component instances regardless of the Parent.

The Operation parameter can be used to not only filter the objects, but also to cast the variable as the right class within the For loop, so in this case, #Member will be a #PRIM_Evp.

Code: Select all

Mthroutine Name(CollectEditableControls)

For Each(#Member) In(#Com_owner.ComponentMembers) Operation(*Instance_Of #Prim_evp)

#avFrameworkManager.avRecordTraceAValue event("Adding Control To Panel Fields") component(#COM_OWNER) avalue(#Member.Name)
#PanelFields<#Member.Name> <= #Member

Endfor

Endroutine
Regards
Stewart Marshall

Independent IT Consultant
www.marshallfloyd.com.au
jyoung
Posts: 694
Joined: Thu Jan 21, 2016 6:43 am
Location: Oklahoma City, OK USA

Re: Changing Field Value Is Not Triggering Changed Event

Post by jyoung »

Hi Stewart,

Thanks for the tip about ComponentMembers, did not know that existed. Will try it out.

I am not trying to do any write processing, just trying to trigger the change so that the Save button gets enabled. I am using a prompt popup panel instead of a dropdown list to allow the user to search for a value. I have a custom "Selected" event that I fire when the user selects a value in the prompter window. I just need to set that value (the one from the event) to the field on the form.

Perhaps I am using the popup panel wrong?

I really thought I had this problem some time ago and had to set the "Modified" property, which is why I as surprised it was not triggering the change.
atostaine
Posts: 696
Joined: Wed Jan 20, 2016 7:38 am

Re: Changing Field Value Is Not Triggering Changed Event

Post by atostaine »

You can define your own Event and signal it instead of setting #CMDBC.Modified := True.

Code: Select all

define_Evt eChanged

Code: Select all

evtroutine handling(#DUNSPopup.Selected) code(#code) description(#description)
#CMDBC := #code
#DUNSPopup.ClosePopup
signal eChanged
endroutine

Code: Select all

evtroutine handling(#PanelFields<>.Changed #com_owner.eChanged)
#phbnSave_enabled := true
endRoutine
Art Tostaine
Post Reply