PyDefUtils not defined error: alert in an embedded Form

I’m trying to get an ‘admin’ button to show up following an alert that tells the user they have logged in in ‘Admin Mode’.

The home page where the button is located is embedded in a parent custom HTML Form The HTML Form is just a banner with an Anvil slot for the standard Form ‘home’ page

An alert->show button approach if I run the home page independently i.e.:

def form_show(self, **event_args):
    self.button_show_data.visible=False
    alert("Admin Mode")
    self.button_show_data.visible = True

But when loading the parent page the alert breaks it with the error:

External. Error: Reference Error: PyDefUtils is not defined

Not sure how to approach this. does anyone know an easy fix for this, or a javascript fix?

Thanks

I’d set a breakpoint at

and single-step from there, to be sure of what’s triggering the error. You might be getting the error message before execution hits that form_show.

1 Like

Thanks, that does isolate the issue.

Its the alert, at that point in the process. The parent HTML app has the Anvil child in its scope, but doesn’t have Anvil’s full functionality., After this point there’s no issue.

If I use anvil.js in the child Form the parent form is OK with that and gives the alerts itself: "an embedded ap at xxx.anvil.app says: “Admin Mode”', which is interesting.

I would get a short delay with a server call and will probably try that.

Different ways to add a banner is probably the real question. Will come back to that. Cheers

Hi @oliverduce,

Thanks for reporting

I believe this should only happen in the Designer, and not when you are running the App, but correct me if I’m wrong.

Moved to bug reports and we’ll get that fixed.

Note - that you probably don’t want an alert in the designer, so you may want to adjust the code

import anvil.designer

...

    def form_show(self, **event_args):
        if anvil.designer.in_designer:
            return
        self.button_show_data.visible=False
        alert("Admin Mode")
        self.button_show_data.visible = True
1 Like

Thanks Stu. This fixes it, very useful. Have published again and confirm its designer only, i.e. works with or without. Thought it was an issue with my approach, but the html form works just fine.

1 Like