Submitting Form widget in modal triggers submit event in SC Catalog Item widget

Yann Dubois2
Tera Expert

Hi,

In my record producer I have a Custom variable that is a widget that opens up the Form widget in a modal window to create a new record that can then populate another variable in the record producer.  This part works quite well.

 

However, when clicking the "Submit" button in the Form widget (modal), it appears to trigger an event that is picked up by the ootb SC Catalog Item widget:

YannDubois2_0-1736294264894.png


This is causing SC Catalog Item widget on the record producer to be set to "submitting" and the action buttons on the widget are greyed out and unavailable to submit the record producer:

YannDubois2_1-1736294364039.png

Is there a practical way that I could modify the Form widget to avoid triggering the same event that the SC Catalog Item widget is listening to?  I've already cloned the ootb Form widget so I modify it to my needs, would prefer, if at ALL possible to keep the SC Catalog Item ootb.

The UI Action that the cloned Form widget is using is the same as the ootb one, which is the sysverb_insert action.  I've thought of creating a new ui action and using that one instead to avoid triggering the same event as the one being listened for in SC Catalog Item, but before I go down a potential rabbit trail I thought I'd ask here in case there's a simpler solution to all of this.

1 REPLY 1

Yann Dubois2
Tera Expert

I found a solution to my problem.  Whether or not it is the best solution may be debatable but it works, so there's that.  I'm open to other solutions!

 

First of all, I had to figure out what was happening.  I learned that the g_form object is shared among all widgets on a given page.  So in my case, it was being shared between both SC Catalog Item widget and the Form widget.  Which meant that when the Form widget did a submit, it triggered the same g_form submit event in BOTH widgets.

 

So, what I ended up having to do was to clone the SC Catalog Item widget and add two lines of code right after the widget initialized event triggers:

YannDubois2_0-1736870871896.png

This code normally should run only once, at widget initialization, but since in my case I'm pulling in the Form widget (through a modal) from a button, it too initializes and triggers this same "spModel.gForm.initialized" event, which in turn is caught by SC Catalog Item again.  The problem arises during this second event.  At this point, the Form widget has overwritten the g_form instance.  As you can see above, this new instance is passed as a parameter, and SC Catalog Item widget will unknowingly overwrite its own instance of g_form with the Form widget's instance.

So in order to keep the two g_form instances separate, I added the check to see if 1) the SC Catalog Item widget already has a non-empty g_form instance, and 2) if so, if that instance is different from the instance being passed in from the event.  If the checks come back as true, then we'll ignore this event and assume it wasn't meant for this widget.

I'd be glad to get any feedback on this solution and any other possible solutions.  I hate having to clone the SC Catalog Item widget just to add these two lines, but I couldn't come up with a better solution.