I may have found a bug, or at least an issue in IntraWeb 15.3.4 that breaks existing IntraWeb applications.
IntraWeb 15.3.x made a change in unit IWRenderContext.pas where procedure TIWPageContext40.AddToJavaScriptOnce(const ACode: string); contains the following code:
The line with "if Pos(LCode, FJavaScript) <= 0 then begin" is introduced in IntraWeb 15.3.x (and was not present in IntraWeb 15.2.69).
This causes problems in our case where we have a page with a TIWControl and an onkeydown Script Event:
The problem is caused in unit IWRenderContext;
The last call to AddToJavaScriptOnce tries to add a JavaScript snippet that only consists of "return true;" and the closing }.
However, inside the AddToJavaScriptOnce, this snippet is found to be already in the FJavaScript (because it's part of the onkeydown Script Event shown in the second screenshot).
As a consequence the last call to AddToJavaScriptOnce has no effect: the JavaScript is not added, and inside the browser we only get the "function Validate(){" without the closing "return true;" and }.
WORKAROUND
A simple workaround is to modify the
And change it into
However, any other place where we only add a "return true;" and "}" will still be ignored, so this may still break IntraWeb applications in other places
FIX?
I do not know the reason why the condition was added to the procedure TIWPageContext40.AddToJavaScriptOnce, but a real fix appears to be to remove that if statement (again, it was not present in IbtraWeb 15.2.69):
Both the workaround and the fix seem to solve the problem for us. Please let me know your thoughts, especially why the new if-statement in the AddToJavaScriptOnce is required, so I can avoid any other issues that may be introduced by my workaround or fix.
Thanks in advance.
Groetjes, Bob Swart
IntraWeb 15.3.x made a change in unit IWRenderContext.pas where procedure TIWPageContext40.AddToJavaScriptOnce(const ACode: string); contains the following code:
Code:
procedure TIWPageContext40.AddToJavaScriptOnce(const ACode: string);
var
len: Integer;
LCode: string;
begin
len := Length(ACode);
if len = 0 then begin
Exit;
end;
if (len > 2) and (ACode[len-1] = CR) and (ACode[len] = LF) then begin
LCode := ACode;
end else begin
LCode := ACode + EOL;
end;
if Pos(LCode, FJavaScript) <= 0 then begin
FJavaScript := FJavaScript + LCode;
end;
end;
The line with "if Pos(LCode, FJavaScript) <= 0 then begin" is introduced in IntraWeb 15.3.x (and was not present in IntraWeb 15.2.69).
This causes problems in our case where we have a page with a TIWControl and an onkeydown Script Event:
Code:
if (event.which == 13) {
console.log("HW");
IWBUTTON_LOGIN_onclick(event);
return false;
} else {
return true;
}
The problem is caused in unit IWRenderContext;
Code:
procedure TIWPageContext40.FinalizeContext;
begin
...
AddToJavaScriptOnce(' return true;' + EOL + '}' + EOL); // last line
end;
The last call to AddToJavaScriptOnce tries to add a JavaScript snippet that only consists of "return true;" and the closing }.
However, inside the AddToJavaScriptOnce, this snippet is found to be already in the FJavaScript (because it's part of the onkeydown Script Event shown in the second screenshot).
As a consequence the last call to AddToJavaScriptOnce has no effect: the JavaScript is not added, and inside the browser we only get the "function Validate(){" without the closing "return true;" and }.
WORKAROUND
A simple workaround is to modify the
Code:
AddToJavaScriptOnce(' return true;' + EOL + '}' + EOL);
And change it into
Code:
AddToJavaScriptOnce(' return true;' + EOL + '} // Bob' + EOL);
However, any other place where we only add a "return true;" and "}" will still be ignored, so this may still break IntraWeb applications in other places
FIX?
I do not know the reason why the condition was added to the procedure TIWPageContext40.AddToJavaScriptOnce, but a real fix appears to be to remove that if statement (again, it was not present in IbtraWeb 15.2.69):
Code:
if Pos(LCode, FJavaScript) <= 0 then begin // prevent LCode to be added to FJavaScript more than once?
FJavaScript := FJavaScript + LCode;
Both the workaround and the fix seem to solve the problem for us. Please let me know your thoughts, especially why the new if-statement in the AddToJavaScriptOnce is required, so I can avoid any other issues that may be introduced by my workaround or fix.
Thanks in advance.
Groetjes, Bob Swart