run client side code before Before Page event of a form

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

Segi
Ebase User
Posts: 649
Joined: Mon Dec 09, 2013 6:37 pm

run client side code before Before Page event of a form

#1

Postby Segi » Thu Mar 17, 2016 8:12 pm

I want to run some client side javascript code to confirm with the user that they want to log off

Code: Select all

var r = confirm("Are you sure you want to log off ?");

if (r==true) { 
	return true;
} else { 
	return false;
}
before the Before Page event has triggered so that if the user clicks on No, the return false statement will prevent the Before Page event from triggering which calls system.securityManager.logoff(); from being called in the Before Page event.

I tried going to the HTML Element Properties and adding a ready and load event with this code but it never gets trigger and I am logged off immediately.

Is it possible to do this ?
0 x

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

#2

Postby Jon » Fri Mar 18, 2016 10:28 am

You can't use client side code on a page before the before page event has run - the reason is that the before page event runs on the server and the server hasn't yet sent the page to the browser. It sounds like your client side event should be attached to whatever the user clicks to logoff e.g. button, hyperlink etc. You could do your check at this point and then return true/false to indicate whether the click should be submitted to the server.
0 x

Segi
Ebase User
Posts: 649
Joined: Mon Dec 09, 2013 6:37 pm

#3

Postby Segi » Fri Mar 18, 2016 11:27 pm

Jon,

The control that triggers the log off is a horizontal menu bar which has a dynamic menu item child. This menu is part of a component that I deploy to multiple forms.

On the Horizontal Menu control, I went into HTML entities and added a click event (after entering an ID of course). For now I added a simple JavaScript alert message for test purposes in the body of the click event.

I deployed the modified horizontal menu with the client side code to one of my forms then load the form in my browser.

When I go into the developer window and go into sources->jQueryEventRegistration, the click event is not there. I don't know if this is a bug or not but my code is not getting deployed along with the menu bar
0 x

kotinkarwak
Ebase User
Posts: 109
Joined: Mon Sep 21, 2015 9:55 pm

#4

Postby kotinkarwak » Sat Mar 19, 2016 7:26 am

Segi,
i am making use of a dymanic menu in a container but using serverside code to perform a logoff among other operations.
It does appear that you can't define "Html Element Properties" for a dynamic control since that would be of nth depth and would need to be defined separately.


highlighted is the dynamic menu part
http://screencast.com/t/uJj6HVQn

In my code, the horizontal menu's click snippet is as follows

Code: Select all

if (new java.lang.String(event.owner.elementName).endsWith("hmenMain")){
	log("WHAT IS SELECTED?: "+ event.getOwner().elementName);

	log("MENU SELECTION: "+ controls.hmenMain.selected);
	switch (controls.hmenMain.selected) {
		case "iHome":
			form.gotoPage(pages.index);
			break;
		case "iCourses":
			form.fields._courseOption.value = "LOCAL";
			form.gotoPage(pages.course);
			break;
		case "iAccount":
			form.fields.fldPager.value = "From Index Page";
			form.gotoPage(pages.profile);
			break;
		case "iSupport":
			break
		case "iPassword":
			form.fields.fldPager.value = "From Profile -iPassword Page";
			form.gotoPage(pages.profile);
			break;
		case "iSignOut":
			system.securityManager.logoff();
			form.gotoPage(pages.index);
			break;
		default:
			break;
	}
		
}
In the above code, the case item refers to the item id or sub menu id defined for the custom menu.
0 x
ebasetech v5

Skype: mateso08
Location: Kenya

kotinkarwak
Ebase User
Posts: 109
Joined: Mon Sep 21, 2015 9:55 pm

#5

Postby kotinkarwak » Sat Mar 19, 2016 7:29 am

delete: duplicate
0 x
ebasetech v5

Skype: mateso08
Location: Kenya


Who is online

Users browsing this forum: No registered users and 26 guests