How to detect changes in entry field?

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

How to detect changes in entry field?

#1

Postby t4nu » Wed Feb 03, 2016 10:34 am

Hi,
I have several pages in a form, and within each form I have edit controls.
I want to detect each change on each edit control, how to do it?
TIA for the help.

Note:
The control can be text edit, check box, radio button or combobox.
0 x

Dave
Ebase Staff
Posts: 89
Joined: Mon Sep 10, 2007 11:48 am

#2

Postby Dave » Wed Feb 03, 2016 11:50 am

Hi - when you say detect, do you mean that you want an event to fire when there is a change of data entered/selected/clicked in any of the edit controls?

If so, one way would be to bind click or change events to the edit controls when the page loads. For example:

Code: Select all

$(document).ready(function(){

   $("*").each (function() {
      if ($(this).get(0).tagName == 'INPUT') {
         $(this).click(function() {trackElement(this);});
      }
      if ($(this).get(0).tagName == 'SELECT') {
         $(this).change(function() {trackElement(this);});
      }
   });

});

function trackElement(element) {
   // do something with element, like maybe a $eb call passing in element.val() or $("option:selected", element).text()
}
If you want to track just certain edit controls you can restrict the event binding by adding a custom attribute value like trackerID=123 in each of the controls (of interest) HtmlElementProperties (Editor Input tab).

Then add that restriction to the bind code above, e.g.

Code: Select all

$(document).ready(function(){

   $("[trackerID]").each (function() {
      if ($(this).get(0).tagName == 'INPUT') {
         $(this).click(function() {trackElement(this);});
      }
      if ($(this).get(0).tagName == 'SELECT') {
         $(this).change(function() {trackElement(this);});
      }
   });

});

function trackElement(element) {
   // do something with element, like maybe a $eb call passing in element.val() or $("option:selected", element).text()
   // or maybe using the trackerID value for something, which by the way is $(element).attr("trackerID")
}
We do this sort of thing when we want to globally track events to pass to Google Analytics.

Dave
0 x

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

#3

Postby t4nu » Wed Feb 03, 2016 2:01 pm

Hi,
Thanks for the respond.
Actually what I want is quite simple (I think). I want to detect the changes in any edit control and then make changes to global variable, so if the user want to leave that page, the data can be save. Something like this:

Code: Select all

  if (isSomethingChange)
      UpdateTheTable();
so if nothing change, the UpdateTheTable() will never be called.
Dave wrote:Hi - when you say detect, do you mean that you want an event to fire when there is a change of data entered/selected/clicked in any of the edit controls?

If so, one way would be to bind click or change events to the edit controls when the page loads. For example:

Code: Select all

$(document).ready(function(){

   $("*").each (function() {
      if ($(this).get(0).tagName == 'INPUT') {
         $(this).click(function() {trackElement(this);});
      }
      if ($(this).get(0).tagName == 'SELECT') {
         $(this).change(function() {trackElement(this);});
      }
   });

});

function trackElement(element) {
   // do something with element, like maybe a $eb call passing in element.val() or $("option:selected", element).text()
}
If you want to track just certain edit controls you can restrict the event binding by adding a custom attribute value like trackerID=123 in each of the controls (of interest) HtmlElementProperties (Editor Input tab).

Then add that restriction to the bind code above, e.g.

Code: Select all

$(document).ready(function(){

   $("[trackerID]").each (function() {
      if ($(this).get(0).tagName == 'INPUT') {
         $(this).click(function() {trackElement(this);});
      }
      if ($(this).get(0).tagName == 'SELECT') {
         $(this).change(function() {trackElement(this);});
      }
   });

});

function trackElement(element) {
   // do something with element, like maybe a $eb call passing in element.val() or $("option:selected", element).text()
   // or maybe using the trackerID value for something, which by the way is $(element).attr("trackerID")
}
We do this sort of thing when we want to globally track events to pass to Google Analytics.

Dave
[/code]
0 x

Dave
Ebase Staff
Posts: 89
Joined: Mon Sep 10, 2007 11:48 am

#4

Postby Dave » Wed Feb 03, 2016 2:35 pm

Sure, so a generic way to do that would be do what's suggested above, i.e. bind an event to every editable control, and then when you detect one of these events just call a function on the server (via the client API) to update your global variable...something like:

Code: Select all

function trackElement(element) {
   $eb.executeFunction("updateMyTableFunction");
}
then later on when the user leaves the page you can do

Code: Select all

if ($eb.executeFunction("hasSomethingChanged")) {
   updateTheTable();
}
0 x

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

#5

Postby t4nu » Mon Feb 22, 2016 7:57 am

May I say that the event when the page loads is the same with Before Page event?
Dave wrote:Hi - when you say detect, do you mean that you want an event to fire when there is a change of data entered/selected/clicked in any of the edit controls?

If so, one way would be to bind click or change events to the edit controls when the page loads. For example:

Code: Select all

$(document).ready(function(){

   $("*").each (function() {
      if ($(this).get(0).tagName == 'INPUT') {
         $(this).click(function() {trackElement(this);});
      }
      if ($(this).get(0).tagName == 'SELECT') {
         $(this).change(function() {trackElement(this);});
      }
   });

});

function trackElement(element) {
   // do something with element, like maybe a $eb call passing in element.val() or $("option:selected", element).text()
}
If you want to track just certain edit controls you can restrict the event binding by adding a custom attribute value like trackerID=123 in each of the controls (of interest) HtmlElementProperties (Editor Input tab).

Then add that restriction to the bind code above, e.g.

Code: Select all

$(document).ready(function(){

   $("[trackerID]").each (function() {
      if ($(this).get(0).tagName == 'INPUT') {
         $(this).click(function() {trackElement(this);});
      }
      if ($(this).get(0).tagName == 'SELECT') {
         $(this).change(function() {trackElement(this);});
      }
   });

});

function trackElement(element) {
   // do something with element, like maybe a $eb call passing in element.val() or $("option:selected", element).text()
   // or maybe using the trackerID value for something, which by the way is $(element).attr("trackerID")
}
We do this sort of thing when we want to globally track events to pass to Google Analytics.

Dave
0 x

Dave
Ebase Staff
Posts: 89
Joined: Mon Sep 10, 2007 11:48 am

#6

Postby Dave » Tue Feb 23, 2016 9:42 am

Sorry - not sure I understand the question.

The Before Page event is an Ebase server-side event, i.e. is executed by the Xi server before a page of HTML is returned to the browser, whilst the $(document).ready() is a client-side event, i.e. executes on the browser after a page of HTML has been received (but before it is presented).

Does this help?
0 x


Who is online

Users browsing this forum: No registered users and 3 guests