Check for changes to field without user input

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

Simon
Ebase User
Posts: 25
Joined: Thu Aug 27, 2009 9:43 am
Location: Hampshire County Council
Contact:

Check for changes to field without user input

#1

Postby Simon » Wed Dec 16, 2009 10:42 am

Hi all

Does anyone know if it is possible to check whether the value in a field has changed when the field is updated within a script? In other words, I need the OnChange event of a field to call a script when the field is set by a script, rather than by the user.

If this is not possible, is there an FPL equivalent of the externalsubmit() Java function, as the script could be attached to the OnValidate event.

Any help would be greatly appreciated ;)

Cheers
Simon
0 x

AJDulk
Ebase User
Posts: 94
Joined: Fri Sep 14, 2007 12:18 pm
Location: The Netherlands
Contact:

Re: Check for changes to field without user input

#2

Postby AJDulk » Thu Dec 17, 2009 10:30 am

I am not sure that you can. The options I can think of:
  • - use "callscript" in the script that changes the field to run the scripts that would normally be run on the field change.
    - use a control field with the on-change scripts attached to the validate option to always check the field.
    - use helper variables that store the value from the last test by the on-change script and use these in the after page event to see whether the on-change scripts need to be called again (using callscript).
0 x

Simon
Ebase User
Posts: 25
Joined: Thu Aug 27, 2009 9:43 am
Location: Hampshire County Council
Contact:

Re: Check for changes to field without user input

#3

Postby Simon » Thu Dec 17, 2009 2:31 pm

Hi AJ, thanks for your reply.
AJDulk wrote:
  • - use "callscript" in the script that changes the field to run the scripts that would normally be run on the field change.
A good idea, but the problem I have is that the field is held in a global component. When the field is changed, it fetches a row from a database resource, which is mapped in the component. However, the field is changed by a script called from the form containing the component; if this script calls the global script that fetches the row, I will need to create and map fields within the form, rather than the component. Since I want this component to be generic and reusable, this would create duplication of effort.
AJDulk wrote:
  • - use a control field with the on-change scripts attached to the validate option to always check the field.
I tried this, but it seems the OnValidate event is only triggered when the user changes the value of the field, rather than a script. Back to square one :P
AJDulk wrote:
  • - use helper variables that store the value from the last test by the on-change script and use these in the after page event to see whether the on-change scripts need to be called again (using callscript).
This is good, and similar to the solution we employed. We created a global script which uses JavaScript to call externalSubmit():

Code: Select all

set GF_HCCGF_MSG__TXT_JAVASCRIPT = '<script>externalSubmit&#40;&#41;;</script>';
which refreshes the page and forces the field to validate. This script can be called from the same script that changes the field value.

To prevent the form from refreshing indefinitely, we used a Boolean field to track whether a change has been detected. This is set to false when the onValidate event is triggered. The externalSubmit is then fired and when the page refreshes, the Boolean is set to true and the JavaScript field is set to blank again.

A bit of a hack, to be sure, but got there in the end!

Cheers man, take care
Simon
0 x

AJDulk
Ebase User
Posts: 94
Joined: Fri Sep 14, 2007 12:18 pm
Location: The Netherlands
Contact:

Re: Check for changes to field without user input

#4

Postby AJDulk » Thu Dec 17, 2009 4:52 pm

AJDulk wrote:
  • - use a control field with the on-change scripts attached to the validate option to always check the field.
Simon wrote:I tried this, but it seems the OnValidate event is only triggered when the user changes the value of the field, rather than a script. Back to square one :P
True if you use the field you are checking itself, you need to create a 2nd field and change its type to "Control Field" (First checkbox in the Field Properties). That field then needs to be placed on the form and the scripts placed in the Validation box. If you have done this and it is not working then that is strange. Scripts in Validation on the Control Field should always fire according to the documentation. I have also used this succesfully in the past.
0 x

Simon
Ebase User
Posts: 25
Joined: Thu Aug 27, 2009 9:43 am
Location: Hampshire County Council
Contact:

#5

Postby Simon » Mon Dec 21, 2009 3:01 pm

Cheers AJ, I see what you're saying, that would definitely work :D
0 x


Who is online

Users browsing this forum: No registered users and 116 guests