B4J Question [ABMaterial] B4JS+B4J 7.80= Not working

MichalK73

Well-Known Member
Licensed User
Longtime User
Hello.
I have the latest version of B4J 7.80 and I noticed that B4JS has stopped working. Even the demo doesn't start. The page is still loading. Can someone check if they work or if I should look for a reason for myself.
ABMaterial ver 4.51

Best regards
 

MichalK73

Well-Known Member
Licensed User
Longtime User
From demo B4JS Chrome
b4js.png
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
Ah, I see. This is a bug in the latest release of ABM in the B4JSMsgbox. In the demo, comment out all the ABM.B4JSMsgbox lines and replace with:

Replace:
B4X:
Select Case Unit.ToUpperCase
   Case "K"
       Page.B4JSMsgbox("msgbox", "The distance is " & (Distance * ToKM) & " kilometers!", "Tutorial", "OK", False, ABM.MSGBOX_POS_CENTER_CENTER, "")
   Case "N"
       Page.B4JSMsgbox("msgbox", "The distance is " & (Distance * ToMiles) & " miles!", "Tutorial", "OK", False, ABM.MSGBOX_POS_CENTER_CENTER, "")
   Case Else
       Page.B4JSMsgbox("msgbox", "No idea what you are doing :-)", "Tutorial", "OK", False, ABM.MSGBOX_POS_CENTER_CENTER, "")
End Select

With:
B4X:
Dim dist As Double
Select Case Unit.ToUpperCase
       Case "K"
           dist = Distance * ToKM
           Log("The distance is " & dist & " kilometers!")
       Case "N"
           dist = Distance * ToMiles
           Log("The distance is " & dist & " miles!")
       Case Else
           Log("No idea what you are doing :-)")
   End Select

And:
B4X:
page.Msgbox("msgbox", "Your complex calculation is now " & ResultLabel.Text, "Result", "OK", False, ABM.MSGBOX_POS_CENTER_CENTER, "")

With:
B4X:
Log("Your complex calculation is now " & ResultLabel.Text)

In the console of the browser, the responses will show instead of an Msgbox.

Alain
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Upvote 0

MichalK73

Well-Known Member
Licensed User
Longtime User
I created a small test with B4JS.
At ABMaterial 4.30 it works very well.
On ABMaterial 4.51 it doesn't work at all. The page is looped.

B4X:
b4js.1568915185870.js: 536 Uncaught SyntaxError: Unexpected token:
template.1568915185870.js: 21 Uncaught ReferenceError: b4js_test is not defined
     at template.1568915185870.js: 21
 

Attachments

  • test.zip
    23.9 KB · Views: 164
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
The .js files @OliverA gave me confirmed that the problem should be in the B4JS Msgbox/Inputbox. I thought the javascript code was not generated if you didn't use it, but it appears it does.

Here is a temporary fix:

In Main, make a new method:
B4X:
Sub TempFixB4JS
   Dim txtIN As TextReader
   txtIN.Initialize(File.OpenInput(File.DirApp & "/www/" & ABMShared.AppName, "b4js." & ABMShared.AppVersion & ".js"))
   Dim s As String = txtIN.ReadAll
   txtIN.Close
   
   s = s.Replace("swaloptions.rtl:","swaloptions.rtl=") '<--- this : should've been an =
   
   Dim txtOUT As TextWriter
   txtOUT.Initialize(File.OpenOutput(File.DirApp & "/www/" & ABMShared.AppName, "b4js." & ABMShared.AppVersion & ".js",False))
   txtOUT.Write(s)
   txtOUT.Close
End Sub

And in AppStart, AFTER StartServer:
B4X:
   ...
   ' start the server
   myApp.StartServer(srvr, "srvr", port)   
   
   TempFixB4JS '<----------------------

Alain
 
Upvote 0
Top