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
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();</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