the backend code seems not executed

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

t4nu
Ebase User
Posts: 305
Joined: Thu Jul 02, 2015 8:32 am
Location: Indonesia

the backend code seems not executed

#1

Postby t4nu » Sun Aug 14, 2016 4:23 am

Hi,
I have a form with a save button and next button.
Both the button has click event code. A rather different is if the user click the next button if will show the confirm() function (executed from HTML element) to ask if the user want to save the data on that page. If he click OK, then it should be trigger the click event of the save button then execute its own code which advance to the next page.
The problem is, if the user click ok, the data is saved but it won't execute the code (backend code), if the user click cancel the backend code is executed as it should be.
What should I do to fix that?
Thanks in advance for the help.
0 x

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

#2

Postby Jon » Mon Aug 15, 2016 8:19 am

At the end of the client Javascript event you should return true or false. True means execute the server event, false means don't execute the server event.
0 x

t4nu
Ebase User
Posts: 305
Joined: Thu Jul 02, 2015 8:32 am
Location: Indonesia

#3

Postby t4nu » Mon Aug 15, 2016 8:57 am

Below is my code:
Basically it should always execute the server event.
The different is if the user choose yes, it will save the data, otherwise skip it.

Code: Select all

var backVal = confirm("Do you want to save data in this page?");

if (backVal)
   $("#saveButton").trigger('click');
     
return true;
Jon wrote:At the end of the client Javascript event you should return true or false. True means execute the server event, false means don't execute the server event.
0 x

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

#4

Postby Jon » Mon Aug 15, 2016 9:03 am

Your code looks fine to me. I don't understand what you mean by..
The problem is, if the user click ok, the data is saved but it won't execute the code (backend code), if the user click cancel the backend code is executed as it should be.
0 x

t4nu
Ebase User
Posts: 305
Joined: Thu Jul 02, 2015 8:32 am
Location: Indonesia

#5

Postby t4nu » Mon Aug 15, 2016 9:16 am

As I stated previously, the code is attached to next button, so if user click it, it should advance to the next page, but before it advance it should ask the user if he wants to save the data on that page first before advance to the next page.

But when the application run, if the user click no, it advance to the next page, the problem is if the user click OK, it won't advance (the save is executed though).

Jon wrote:Your code looks fine to me. I don't understand what you mean by..
The problem is, if the user click ok, the data is saved but it won't execute the code (backend code), if the user click cancel the backend code is executed as it should be.
0 x

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

#6

Postby Jon » Mon Aug 15, 2016 10:26 am

I wonder if the two server events are running at the same time and interfering with each other.
The line:

$("#saveButton").trigger('click');

should execute the on-click server event for the save button.

and the line:

return true;

should execute the on-click server event for the button that has been clicked.

If you run the form from the designer, what do you see in the execution log? You should see messages for both buttons e.g.

Button (ButI5Tsz) clicked
Running On Click event for Control ButI5Tsz
Executing Javascript script CloudStatsTest_1
0 x

t4nu
Ebase User
Posts: 305
Joined: Thu Jul 02, 2015 8:32 am
Location: Indonesia

#7

Postby t4nu » Mon Aug 15, 2016 11:56 am

Here is what I take from the log:

When I choose "OK" means I want to save first then move to next page

18:34:51.264 Info : Button (btnFamSave) clicked
18:34:51.264 Info : Running On Click event for Control btnFamSave
18:34:51.264 Info : Executing Javascript script DataKeluargaControlEvents


and here is when I choose "Cancel", means directly move to the next page

18:37:46.768 Info : Button (btnFamNext) clicked
18:37:46.768 Info : Running On Click event for Control btnFamNext
18:37:46.768 Info : Executing Javascript script DataKeluargaControlEvents


Jon wrote:I wonder if the two server events are running at the same time and interfering with each other.
The line:

$("#saveButton").trigger('click');

should execute the on-click server event for the save button.

and the line:

return true;

should execute the on-click server event for the button that has been clicked.

If you run the form from the designer, what do you see in the execution log? You should see messages for both buttons e.g.

Button (ButI5Tsz) clicked
Running On Click event for Control ButI5Tsz
Executing Javascript script CloudStatsTest_1
0 x

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

#8

Postby Jon » Tue Aug 16, 2016 8:24 am

Presumably when you click OK you want to see events for both buttons being fired. I don't think this can be made to work. I suspect that it isn't possible to execute anything in the client browser beyond:

$("#saveButton").trigger('click');

This simulated button click will return page updates to the browser and the browser state will be reset. So the next line - return true - probably never gets executed.

I think you will have to rewrite this a different way. You could use a $eb.executeFunction() statement instead of the button click, then it should work OK e.g.

Code: Select all

var backVal = confirm("Do you want to save data in this page?");

if (backVal)
   $eb.executeFunction("saveData"); 
     
return true; 
0 x

t4nu
Ebase User
Posts: 305
Joined: Thu Jul 02, 2015 8:32 am
Location: Indonesia

#9

Postby t4nu » Tue Aug 16, 2016 8:56 am

Hi,
The save button actually just issue the updateTable() method, if I put it in the clientcallablefunction can I still do the same thing or I should do extra things?

My experiences with clientcallable function seems that the state of the database resource in the client callable function and in the page that call it seems different. What I mean is if in the caller page the state is rowisinserted or rowismodified, but from within the client callable function seems no state.

Sorry due to my load, I haven't have a chance to try it.
Jon wrote:Presumably when you click OK you want to see events for both buttons being fired. I don't think this can be made to work. I suspect that it isn't possible to execute anything in the client browser beyond:

$("#saveButton").trigger('click');

This simulated button click will return page updates to the browser and the browser state will be reset. So the next line - return true - probably never gets executed.

I think you will have to rewrite this a different way. You could use a $eb.executeFunction() statement instead of the button click, then it should work OK e.g.

Code: Select all

var backVal = confirm("Do you want to save data in this page?");

if (backVal)
   $eb.executeFunction("saveData"); 
     
return true; 
0 x

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

#10

Postby Jon » Tue Aug 16, 2016 9:45 am

The save button actually just issue the updateTable() method, if I put it in the clientcallablefunction can I still do the same thing or I should do extra things?
Just updateTable(). This doesn't change the visual state so you should be fine.
0 x

t4nu
Ebase User
Posts: 305
Joined: Thu Jul 02, 2015 8:32 am
Location: Indonesia

#11

Postby t4nu » Tue Aug 16, 2016 11:43 am

Thank you, Jon.
Jon wrote:
The save button actually just issue the updateTable() method, if I put it in the clientcallablefunction can I still do the same thing or I should do extra things?
Just updateTable(). This doesn't change the visual state so you should be fine.
0 x

t4nu
Ebase User
Posts: 305
Joined: Thu Jul 02, 2015 8:32 am
Location: Indonesia

#12

Postby t4nu » Wed Aug 31, 2016 5:17 am

Hi,
I change the code to:

Code: Select all

var backVal = confirm("Do you want to save data in this page?");

if (backVal)
{
    SaveIt();
}


return true;


function SaveIt()
{
   var ok2Continue = 0;
   var pageTitle = $("#pageTitle").text();

   ok2Continue = $eb.executeFunction("SavePage", [pageTitle], true);
      	
     if &#40;ok2Continue < 0&#41;
     &#123;
        if &#40;ok2Continue == -1&#41;
          alert&#40;"Saving Data on page " + pageTitle + ", failed!"&#41;;
     &#125;
&#125;
Still the server side is not triggered.
Jon wrote:Presumably when you click OK you want to see events for both buttons being fired. I don't think this can be made to work. I suspect that it isn't possible to execute anything in the client browser beyond:

$("#saveButton").trigger('click');

This simulated button click will return page updates to the browser and the browser state will be reset. So the next line - return true - probably never gets executed.

I think you will have to rewrite this a different way. You could use a $eb.executeFunction() statement instead of the button click, then it should work OK e.g.

Code: Select all

var backVal = confirm&#40;"Do you want to save data in this page?"&#41;;

if &#40;backVal&#41;
   $eb.executeFunction&#40;"saveData"&#41;; 
     
return true; 
0 x

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

#13

Postby Jon » Wed Aug 31, 2016 8:14 am

Do you mean the $eb.executeFunction is not executed? I would add some alerts to the Javascript to find out what is happening. Or better still, use interactive debug in the browser.
0 x

t4nu
Ebase User
Posts: 305
Joined: Thu Jul 02, 2015 8:32 am
Location: Indonesia

#14

Postby t4nu » Wed Aug 31, 2016 9:17 am

the $eb.executeFunction is executed. But seems the return true is ignored.
So the page is not advance to other page, still on the same page.
Jon wrote:Do you mean the $eb.executeFunction is not executed? I would add some alerts to the Javascript to find out what is happening. Or better still, use interactive debug in the browser.
0 x

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

#15

Postby Jon » Wed Aug 31, 2016 9:36 am

Oh, I don't know why it behaves like that. Why not just remove "return true"? - the default is to submit any server-side event after the client-side event, which is what you want.
0 x

t4nu
Ebase User
Posts: 305
Joined: Thu Jul 02, 2015 8:32 am
Location: Indonesia

#16

Postby t4nu » Thu Sep 01, 2016 5:57 am

Still not working.
Really frustrating :(

Anyway thanks for the help.
Jon wrote:Oh, I don't know why it behaves like that. Why not just remove "return true"? - the default is to submit any server-side event after the client-side event, which is what you want.
0 x


Who is online

Users browsing this forum: No registered users and 20 guests