Make self.call_js available for blank page?

Hi,

I find that self.call_js is NOT available for blank page thanks to the very clear explanation below.
Is there a way to make it work? Since blank page is my way to create a Master–detail interface.

Any hint is greatly appreacited.

I’m not certain about all these details, but might help…

  • Blank Panel forms can call javascript functions using anvil.js.call_js (or just js.call_js)

  • if a javascript function is registered somewhere in the app then that function will get called. Even from a BlankPanel Form

  • The special thing about HTML Forms is that they have their own script tags.
    But it’s not that special since doing self.call_js can also call other registered functions in the app.

  • An issue with the BlankPanel is that there’s no way to use anvil.call to call a method inside the BlankPanel Form from javascript.

  • If you need to use anvil.call from javascript then it will only find functions within an HTML Form… if this is the use case then a BlankPanel Form is not usitable

2 Likes

Thanks so much @stucork, unfortunately, I got the error (hideSidebar is the default function of anvil app):

anvil.js.call_js("hideSidebar") #auto complete  not available

Could not find global JS function 'hideSidebar'

Make sure both form’s show events have been triggered. Can follow up with more if you have a clone.

Thanks so much @stucork. I learn a lot from you and really appreciate that. Here is the link

So, this isn’t an answer to the original question (how to call_js from a blank page, which I also can’t get to work), but for a couple years now I just use a blank HTML page whenever I would otherwise use a blank page. It fills the same usage role in Anvil for me, and gives me access to self.call_js, and allows me to customize the HTML for that form if needed.

3 Likes

the reason it doesn’t work is because Form1 is not in the app and so 'hideSidebar' is not a registered function.

a small tweak to your version and it works fine…
https://anvil.works/build#clone:7PBTVN7YFBO4G2JY=M723BHBUIXJVOJZQSM57ILD7

2 Likes

Thanks so much @stucork, it works perfectly well

1 Like

Hi there

Your solution makes me curious - I’m trying to insert the tags to Google Fonts into html for usage by a blank form which doesn’t work for obvious reasons.

When you say blank HTML page, what html file do you use to refer that page to? Is the HTML file also totally blank or could you send me the code for that? I’m a total html beginner so please excuse any ignorance in these questions! But what I’d like to do is use a custom html form with an html file that allows the form to behave exactly like a Blank Panel form while also referencing the font tags in the html file.

Thanks

Follow-up…got it to work thanks. HTML file indeed blank apart from the font tags

1 Like