“‘X’ Gon Give It To Ya”: Monitor the Close Event of a Subview Closed by a Window Border Control (the “X” button)

Here’s the scenario: A user closes a subview by clicking on the “X” button its window, messing up your order of rule execution AND the demo of your work to the client.

Not that that really happened (oh yes it did).

Well, I’m not angry about it or anything (oh yes I am).

I spent several hours running through the entire chain of events and possible actions. And all of them worked correctly in EVERY instance — before I thought to test what would happen if the user closed the subview using that blasted “X” button in its window.

And what I found were three things: (1) clicking on that “X” control will abort normal rule execution, which (2) reproduced the behavior we saw during the demo, and (3) the window controls’ events are not captured by K2 SmartForms.

Well. Not without a little help.

Scenario: Deeper Dive

Given a form containing two views — an item view with some controls for actions, and a list view that takes orders from the action view. The item view has rules which call up a third view as a subview, which closes after some work is done.

The subview has no actionable controls, with exception of the standard border controls that appear around any subform or subview. Those controls are a maximize button (resembling a box) and a close button (resembling an “X”) which mimic standard Windows controls.

subview

The rules were essentially that a click of a button on the item view would start some operations which would eventually invoke the subview and terminate in re-initializing the item view, causing the list view to refresh (I’m sort of over-simplifying).

The user closing the subview with that “X” control caused the rule execution to abort, leaving the views in their current state, and giving the client the impression that the operations didn’t work.

So I needed a way for the form to reinitialize the item view when the subview closes.

Now, you can create a rule in the form that listens for the “When a subview is closing” event, but it won’t fire. That’s because the close event, when triggered by the border control, doesn’t have a handler that K2 SmartForms knows about…

…so it’s up to us to make one.

Steps

  1. On the subview, create a hidden button, and create a rule for that button’s click event and assign to it the “Close a subview or subform” action (it’s listed under “Subview Interaction” in the Rule Designer). Save it and check the subview back in.

    Now your form has a close event to listen for.

  2. All that’s left is to create a rule on your form for the event “When a subview is closing,” and assign to it whatever action is supposed to happen in your normal ruleset. In my case, it was to execute the Initialize() method on the action view. Save, check it in, and test.

You should find that the form will now detect the close event triggered by the “X” button and will fire the actions you’ve specified.*

What Have We Done?

Having followed these instructions, I feel it’s important to review what we have done and what we haven’t.

  • In this post, we’ve discovered that controls on the border of a SmartForms window are NOT monitored by SmartForms event listeners. This is a really significant discovery.

  • In the case of the “X” (close window) click, we’ve learned we’re able to get around the inability to monitor the click event by creating a control with an event that mimics it. We’re able to handle that event in the form to produce a desired result.

  • *We’re not able to directly handle the “X” click; we’re able to handle the action of the subview closing. The net effect is the same, but we’re addressing the result, not the actual cause.

It’s indistinguishable to the user, but an important distinction behind the scenes.
 
 
 
 
 
X Gon Give it to Ya © Sony/ATV Music Publishing LLC, Kobalt Music Publishing Ltd., Warner/Chappell Music, Inc

“‘X’ Gon Give It To Ya”: Monitor the Close Event of a Subview Closed by a Window Border Control (the “X” button)

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s