Recently we had the need to determine in Javascript whether the form on a launch-page created with HTML Composer did validate or not.
As it is, IBI's javascript checks whether required fields are filled or not. If not, they put a red border around those required fields that don't have a value.
When a form gets submitted, we have access to a function:
function buttonN_onclidk(ctrl) {
OnExecute(ctrl);
}
Unfortunately, ONExecute() does not return
anything at all!
So, how to determine whether above mentioned form validated (the required fields were filled in) or not?
Well, this is Javascript, where we can assign function declarations to variables and vice versa, so we can
wrap IBI's function in
our own implementation!
The relevant function in this case is: function isValueSet(IbControlValue,checkForEmptyValue) {...}
Here's the code to wrap it:
<SCRIPT id=clientEventHandlersJS type=text/javascript>
var executeResult; // Global variable that keeps track of the form validation result
var originalIsValueSet;
function window_onload() {
UpdateData();
// Keep a copy of IBI's isValueSet function
originalIsValueSet = isValueSet;
// Replace it with our own function
isValueSet = ourIsValueSet;
}
function ourIsValueSet(IbControlValue,checkForEmptyValue) {
var result = originalIsValueSet(IbControlValue,checkForEmptyValue);
if (!result)
executeResult = result;
return result;
}
function button1_onclick(ctrl) {
// Initialize form validation result
executeResult = true;
// Validate and execute form
OnExecute(ctrl);
// Use the form validation result (we return it in this case)
return executeResult;
}
</SCRIPT>
Of course, this approach can be used for other IBI-internal Javascript functions as well. Just make sure you pass enough function parameters.
WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :