How to retain jQuery settings post a server refresh

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

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

How to retain jQuery settings post a server refresh

#1

Postby kotinkarwak » Wed Sep 30, 2015 1:43 pm

Put together a short jing video to show the query.
http://screencast.com/t/zypjRZsWBL
Regards
0 x

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

#2

Postby Jon » Wed Sep 30, 2015 2:10 pm

I think the problem is that you are using the document.ready event to set up your jquery bindings. This runs only when the page is first loaded. I think you are also using Ajax as well - click on Form Properties on the form editor toolbar and look on the General tab. So what happens is that when you click on something which sends a request to the server (retrieve previous application?) the page is refreshed using Ajax (but not replaced) and your jquery bindings are lost. This combination of document.ready and Ajax frequently causes problems.

The solution is to use the ready event on one of the controls on the page instead of document ready. For example you might move the date picker binding to the date field that it is working on. Or you might move all the jquery code to the Page Panel Control containing all your fields. To configure this, right click on the control in question and select Html Element Properties. In this dialog, provide an id (this is required to bind the event) then add a jquery ready event with your code.

P.S. I liked the video!
0 x

Steve James
Ebase User
Posts: 331
Joined: Mon Mar 10, 2014 8:34 am

#3

Postby Steve James » Fri Oct 02, 2015 2:02 pm

The other way is to keep it on the document ready but have a flag to set it only on initial load eg get/set field value.

We've occasionally had issues where we know we've attached html element properties but finding the actual element can be time consuming.

Hopefully v5 will make it easier to see in the tree what has got 'stuff' attached to it.

Thanks
0 x

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

#4

Postby kotinkarwak » Sun Oct 04, 2015 10:54 am

Thanks Jon, Steve,
Steve, please expand your answer on how you do this sine it appears document ready only runs one when I try.
0 x

Steve James
Ebase User
Posts: 331
Joined: Mon Mar 10, 2014 8:34 am

#5

Postby Steve James » Mon Oct 05, 2015 7:47 am

Hi kotinkarwak, sorry but I think I misunderstood the issue, we've put the flag on in situations where the code was called multiple times.
0 x

User avatar
Wai
Moderator
Moderator
Posts: 165
Joined: Wed Sep 12, 2007 9:04 am
Location: Sandy, UK
Contact:

#6

Postby Wai » Sun Jan 31, 2016 1:06 pm

Hi,

Instead of using the standard JQuery document.ready which will only execute when the whole page is refreshed, you can use the Ebase Ready event.
Each control, for example the Page control, or a field control has a JQuery Ready event which can execute your code when the control is refreshed by Ebase (when form is using Ajax).

Therefore after Ebase server execution, when a control is refreshed, it will fire the Ready event on the control.

You can place your datepicker JQuery code into the Page control Ready event.

For example:

Code: Select all

$(".datepicker2").datepicker({
		showOn: "button",
		buttonText: 'Select Date',
		buttonImage: "images/calendar.gif",
		buttonImageOnly: true,
		dateFormat: 'dd/mm/yy',
		showButtonPanel: false,
		changeMonth: true,
		changeYear: true
	});
0 x

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

#7

Postby kotinkarwak » Fri Mar 04, 2016 7:56 am

Implementing jsTree and utilising a tab control. As per this thread, I have added the initialisation of the jsTree from within the controls "onready" setting but does not appear to be working.

Initial load of the page correctly sets the tree in TAB A, but if you navigate to another tab and return, the setting is not being done again.

v501 export file
https://mega.nz/#!jMRyQYhI!mtKht7hklZkz ... b9iWT1p_9Y
0 x
ebasetech v5

Skype: mateso08
Location: Kenya

User avatar
Wai
Moderator
Moderator
Posts: 165
Joined: Wed Sep 12, 2007 9:04 am
Location: Sandy, UK
Contact:

#8

Postby Wai » Fri Mar 04, 2016 9:19 am

Try putting the initialisation on the Page control's Ready event.
0 x

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

#9

Postby kotinkarwak » Fri Mar 04, 2016 9:26 am

Hi,
Thanks Wai, works with the pages onready control. just for info: need to remove all entries elsewhere that does this same operation i.e. I had the same code added to the the pages onready in the tab control itself and that caused whole operation to fail.

a side note

i understand you can chain "methods" in javascript api's. Had untold inconsistencies when running my ebase code once I run this bit of code as chained. After unchaining, all works ok. Might help someone when they encounter some errors, try unchaining the code and see what happens

Code: Select all

jQuery('#jstree_demo_div').jstree().on("changed.jstree", function (e, data) {
  console.log(data.selected);
0 x
ebasetech v5

Skype: mateso08
Location: Kenya


Who is online

Users browsing this forum: No registered users and 13 guests