Self.call_js not working in "Blank Panel" Form

I’m refactoring some code from an existing anvil project that was meant to demo some chat functionality:
https://anvil.works/build#clone:X3NLEWNXN7EKTRVA=Z25OY6KF7Q26MPLO4BOUCJJS

From this post: Hangouts-like Chat Design

Basically I moved all the functionality of “Form1” into a separate blank panel in my app called “Chat”:
https://anvil.works/build#clone:S7AEDKOUANCRZ7GZ=UE5NXL6JNWVOBTICIWPUDD2Y

What is throwing me for a loop is… whenever I send a new message I’m getting this error:
AttributeError: 'Chat' object has no attribute 'call_js' at Chat, line 22

Any ideas?

I’m guessing your Chat Form is a Blank Panel form… only HTML Forms have a self.call_js method. I got thrown by this one recently.

You can do js.call_js but since you don’t have an HTML Form in your app it will still fail since this doesn’t mean anything (this refers to the HTML Form that you are calling from)

Here’s a clone link using the BlankPanel Forms - I had to move the function to native libraries and replace this with $(document)
https://anvil.works/build#clone:HBOQN5LWLF6Z625D=3PUW7P5FMRQVQO5KAHOAWLSC

I would maybe think about a re-refactor into a Custom HTML form and use self.call_js

1 Like

Hi @nathanguyette,

Yes, as @stucork says, BlankPanel Forms do not have a built-in call_js method. I’m going to update the docs to make this a little clearer! There are two options, as @stucork has said: use a Custom HTML Form and self.call_js(), or use the global anvil.js.call_js() to call a function in Native Libraries.

I’ve tweaked your example slightly to turn your ‘Chat’ Form into a CustomHTML Form - that now contains the scrollCard function that will be called when a new message is added to the chat:

https://anvil.works/build#clone:BZ6HC5YDQRT7U2SF=VQN2DBPZ6LMPCI62B5PHC5TA

2 Likes

@bridget, thanks!

Though that does lead me to another question… Where in the anvil IDE does it show that a Form is “Custom HTML” or “Blank Panel” or a “Standard Page” ?

in the design view if you have self selceted you can check if it has an HTML component or not.

If it does it’s an HTML Form if it doesn’t it’s a BlankPanel

Screen Shot 2020-02-28 at 07.28.58