cancel
Showing results for 
Search instead for 
Did you mean: 

MDK - Event triggered multiple times because of redraw

498

Hello MDK- Team and Experts,

I have noticed that if there is a button in a section of the MDK app which gets refreshed using redraw, when this button is pressed, the event handler added for OnPress is triggered multiple times. Any new redraw will add a new subscription to this event.

We are using MDK version 23.4 and we have this issue in several places. This affects the functionality of the apps. We need redraw so that the page reacts to changes of flags and the proper data is displayed in the page.

  • Can this "refresh" be performed in a way that doesn't register the event again?
  • Is there any other way to refresh the content of a section without using redraw?
  • Is there any way to identify based on some flags (maybe from clientAPI) if the button was pressed by the actual user and not something triggered automatically?
  • Can you somehow "unsubscribe" the event handler before redraw and then register it back?

Any help/suggestions are highly appreciated.

Thank you,

Anca

Accepted Solutions (0)

Answers (1)

Answers (1)

bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

Redrawing a page will not trigger the OnPress handler of a button. Can you please confirm the specific MDK 23.4.x version you are using? The latest version is MDK 23.4.2.

Can you provide more details on your scenario. Maybe attach the page metadata and assuming the OnPress is a rule the contents of that rule?

0 Kudos

Redrawing a page/section does not trigger the onPress event but it registers it again. When you end up actually pressing the button, the event handler of that button will be called multiple times. The number of times it is called is increased after each redraw.

We are using MDK 23.4.2 version. Here is the code to a sample POC app created just to demonstrate this issue. The button from the footer of the section triggers the event handler only once but the one from the page footer triggers it multiple times.

Our issues are caused by the page redraw. In the meantime we were able to find some workarounds and not use it anymore but maybe in the future some feature will require an actual page redraw and we will face the same issues.

Here is a short gif demo: redrawissuedemo.gif

RedrawIssue.page

{
	"Controls": [
		{
			"_Type": "Control.Type.SectionedTable",
			"_Name": "RedrawIssuePageContent",
			"Sections": [
				{
					"Separators": {
						"TopSectionSeparator": false,
						"BottomSectionSeparator": true,
						"HeaderSeparator": true,
						"FooterSeparator": true
					},
					"KeyAndValues": [
						{
							"Value": "{#Application/#ClientData/sText}",
							"_Name": "KeyValue0",
							"KeyName": "KeyName",
							"Visible": true
						}
					],
					"MaxItemCount": 1,
					"_Type": "Section.Type.KeyValue",
					"_Name": "RedrawIssueSectionKeyVal",
					"Footer": {
						"_Name": "SectionFooter0",
						"Caption": "Press to trigger",
						"Visible": true,
						"OnPress": "/OrderProducts/Rules/RedrawIssues/TriggerOnPress.js",
						"UseBottomPadding": false
					},
					"Visible": true,
					"EmptySection": {
						"FooterVisible": false
					},
					"Layout": {
						"NumberOfColumns": 2
					}
				}
			]
		}
	],
	"_Type": "Page",
	"_Name": "RedrawIssue",
	"Caption": "RedrawIssue",
	"PrefersLargeCaption": true,
	"ToolBar": {
		"Items": [
			{
				"_Type": "Control.Type.ToolbarItem",
				"_Name": "ToolbarItem2",
				"Caption": "Redraw",
				"Enabled": true,
				"Visible": true,
				"Clickable": true,
				"Style": "",
				"OnPress": "/OrderProducts/Rules/RedrawIssues/RedrawOnPress.js"
			},
			{
				"_Type": "Control.Type.ToolbarItem",
				"_Name": "ToolbarItem3",
				"Caption": "Trigger",
				"Enabled": true,
				"Visible": true,
				"Clickable": true,
				"Style": "",
				"OnPress": "/OrderProducts/Rules/RedrawIssues/TriggerOnPress.js"
			}
		]
	}
}

RedrawOnPress.js (rule)

export default function RedrawOnPress(clientAPI) {
	const oPageProxy = clientAPI.getPageProxy();

	// refresh page - duplicates the registration of the event handlers but is needed in some cases where
	// based on certain action/flags entire sections should be displayed/hidden
	oPageProxy.currentPage.redraw();

	// refresh page content - does not create duplicate registration of the event handlers
	oPageProxy.getControl("RedrawIssuePageContent").redraw();

	// refresh section - does not create duplicate registration of the event handlers
	oPageProxy.getControl("RedrawIssuePageContent").getSection("RedrawIssueSectionKeyVal").redraw();
}

TriggerOnPress.js (rule)

export default function TriggerOnPress(clientAPI) {
	const oAppClientData = clientAPI.getAppClientData();
	oAppClientData.sText += "+";
	alert(oAppClientData.sText);
}
bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

anca.barbulescu Can you pleas confirm what device / emulator you are using and what OS version it is running? I setup your reproduction example and am unable to reproduce it on my Pixel 6 phone (Android 13) or on my emulator.

0 Kudos

I've run not the POC app on android emulator (android 13) and I was not able to reproduce this also. The demo was done on web version, here the issue is reproducible.

bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

The gif demo appears to be done on an Android device/emulator not the web. Please confirm what platform you are targeting for this capability?