Way to reset child web block?

Way to reset child web block?

  
Hi. I'm hoping someone in the OutSystems community can help me out.

I have created a simple Web Block Widget (called SearchGo) with an input and a button. The button notifies the parent of SearchGo by sending an ajax message using "NotifyParent". The parent receives the message using the On Notify action and gets the content of the message using "NotifyWidgetGetMessage". This is a very simple example.

I have a reset all button in the parent. When this button is clicked, I reset all the inputs on the web page to their defaults. I simply set the inputs' variables to their respective default values and perform an ajax refresh on each input. What I can't figure out how to do is reset the input field in the child GoSearch Web Block.

Ideally, the variable for the input field in the GoSearch Web Block should remain invisible/inaccessible to the parent. I know I could use a session variable instead and then perform an ajax refresh on GoSearch, but this GoSearch is used on multiple pages and I don't want to have to clear that session variable in a million places. Is there any way I can notify the GoSearch child Web Block from its parent to reset itself?
And I figured it out!

If I use an input variable in the SearchGo Web Block Widget instead of a local variable I can reset the value of that variable in the parent and then ajax refresh its SearchGo. This keeps the variable shared between the two.

I hadn't thought of this until after my post. I assumed once a variable is passed into a child on creation, a new instance of that variable was created locally within the child. Apparently not as they remain shared.

Thanks Joost for the answer that led me to try this at: http://www.outsystems.com/forums/discussion/7685/web-block-communication/
HI.

If what you want is to clear it, not change it, here is an easier way than that: if the WebBlock has a Preparation to reset the input field, you just call a refresh from the parent.

Side effects: when you call the notification, it will also clear the variable. But by then the value is already in the parent so it is no longer needed in the webblock.

I attached a basic example made in version 7.
Apologies... I just gave a little misinformation.

A new instance of the variable is indeed instantiated (a copy is made) so the variable is NOT shared between parent and child. However, this still works for me.

An ajax refresh actually causes the child Web Block Widget (SearchGo) to reinitialize. I'm not sure if just the Preparation and some obfuscated initialization code is recalled or if an entirely new instance of the child Web Block Widget is created, but for me it doesn't matter. What does matter for me is that the parent sends in the input variable again and a new copy of this input variable from the parent is stored locally in the child Web Block Widget.

Nate
Nuno Reis wrote:

Thanks Nuno! That would work as well. I'm not sure why I didn't think of it.

Nate
HI.

If what you want is to clear it, not change it, here is a way easier than that: if the WebBlock has a Preparation to reset the input field, you just call a refresh on the parent.

Side effects: when you call the notification, it will also clear the variable. But by then the value is already in the parent so it is no longer needed in the webblock.

I attached a basic example made in version 7.