Checkbox in a Session Variable

  

Hi,

I'm testing the behavior of a checkbox that persists even if we reload and change the web screen. I had tried storing the Checkbox widget in a Session Variable, set a Screen Action as the On Change destination to store the session variable in the server. In this Action I have an Ajax refresh and I refresh the CheckBox widget.


Expected behavior: Check the checkbox, navigate to another webscreen and you come back the widget keed checked


Actual behavior: The checkbox widget try to be checked and go to uncheck itself 

Hi Luis,

You use a table records on the person entity, but then you bind the checkbox to a session variable.

Not sure what you intend to achive with the checkbox. The onchange only does an ajax refresh of the checkbox, that doesn't make sense either. Your session.checkbox value will be set to every row's checkbox.

If you intend to use the checkbox to select rows, you should add an attribute to the aggregate with value false, and than bind the checkbox to the aggregate.

Regards,

Daniel

Daniël Kuhlmann wrote:

Hi Luis,

You use a table records on the person entity, but then you bind the checkbox to a session variable.

Not sure what you intend to achive with the checkbox. The onchange only does an ajax refresh of the checkbox, that doesn't make sense either. Your session.checkbox value will be set to every row's checkbox.

If you intend to use the checkbox to select rows, you should add an attribute to the aggregate with value false, and than bind the checkbox to the aggregate.

Regards,

Daniel

Hi Daniel, thanks for the reply. Can I achieve the expected behavior without adding an attribute?

I want to achieve check the checkbox, leave the navigate to another webscreen, when coming back having the checkbox checked


Solution

Luis,

Besides what Daniel explained about how to properly setup a checkbox in a TableRecords, there are other aspects to take into account.

1. Adding a field to the aggregate that feeds the TableRecords and bind this new attribute, from the TableRecords list to the check box is a non persistent method. If you leave the screen this information will be lost.

2. The OnChange will not navigate to another screen. It will call a Screen Action using Ajax Submit. If you put the check box inside a container and set ALSO the OnClick of it, you will probably see this behaviour where the checkbox keeps its original state. Use the OnClick alone will not see the new value in the Check Box.

In any case, if you want to keep value after coming back from the page to where you navigate, you will have to save this to database. Any other option will greatly decrease application performance.

I suggest you to avoid navigating to other screen. Instead, Open a Popup or use a modal. 

To open a popup from the OnChange, you will need to click, from code, a hidden link in the page, associated to a Popup editor. You will need JavaScript (use RunJavaScript from HttpRequestHandler): "$('#" + LinkName.Id + "').click();"

The modal can be opened using ToogleModal. It is in the page itself.

Both will guarantee you don't lose the data associated to the check boxes.

Hope this helps.

Cheers.



Solution

Eduardo Jauch wrote:

Luis,

Besides what Daniel explained about how to properly setup a checkbox in a TableRecords, there are other aspects to take into account.

1. Adding a field to the aggregate that feeds the TableRecords and bind this new attribute, from the TableRecords list to the check box is a non persistent method. If you leave the screen this information will be lost.

2. The OnChange will not navigate to another screen. It will call a Screen Action using Ajax Submit. If you put the check box inside a container and set ALSO the OnClick of it, you will probably see this behaviour where the checkbox keeps its original state. Use the OnClick alone will not see the new value in the Check Box.

In any case, if you want to keep value after coming back from the page to where you navigate, you will have to save this to database. Any other option will greatly decrease application performance.

I suggest you to avoid navigating to other screen. Instead, Open a Popup or use a modal. 

To open a popup from the OnChange, you will need to click, from code, a hidden link in the page, associated to a Popup editor. You will need JavaScript (use RunJavaScript from HttpRequestHandler): "$('#" + LinkName.Id + "').click();"

The modal can be opened using ToogleModal. It is in the page itself.

Both will guarantee you don't lose the data associated to the check boxes.

Hope this helps.

Cheers.



Hi Eduardo, if you see the module I share, I have both the container and the checkbox with an OnClick and OnChange Screen Actions associated, even though I don't see the expected behavior. Honestly, I consider that saving in the database a temporary state of false is the best option. So the expected behavior could not be recreated smoothly in OutSystems. Thanks.