Click event for File Loader

Edit: I’ve turned this question into a FR.

Is it possible to have a “click” event on a File Loader component?

That is, when a user clicks on a File Loader, it opens the file explorer. I’d like to do this programatically. This way I can trigger the file explorer to open based on any other event that has taken place.

For example, suppose I want users to design a visualization, but they have to load their files first. If they attempt to make a visualization without loading files, I would currently have to alert them to this and direct them to click the file loader component. It would be great if I could just trigger the file loader if they have not loaded any files.

Another use case is related to style. For example, (see below) the file loader does not look very nice in the nav bar, but a link does, therefore, I could trigger the file loader behaviour via a link’s click event (avoiding the need for CSS).

ezgif.com-crop (7)

1 Like

i’ve update anvil augment to make this work
https://anvil.works/build#clone:S37QUKVBHY6QKBM4=VNLRIPIRVN5HXZK3FPAG37PG

from AnvilAugment import augment

augment.add_event(self.file_loader, 'click')

def link_click(self, **event_args):
    self.file_loader.trigger('click')
3 Likes

That is fantastic! I’ll be making use of that today. Augment has been very helpful with the current project I’m working on. In particular, I love having a click event on non-links haha. Thanks a ton Stu!

1 Like

Thanks again @stucork. Tried this today and it works perfectly. Awesome!

Hi @alcampopiano,

I agree that this would be a nice addition - added to the list! :slight_smile:

1 Like

I’m trying to do this exact thing, but when I try to implement it as shown I get an:

ImportError: No module named AnvilAugment

A clone of the example provided works, but it doesn’t in my app?

Really confused?

Ok, I figured it out!

Have to clone the AnvilAugment app, then add it as a dependency.

Fantastic, thanks for creating this.

2 Likes

Slight necropost, but I couldn’t think of anywhere better to put it.

You can import augment from anvil extras now if you have it as a dependency -

from anvil_extras import augment

The rest stays the same. Might be useful to someone (it was for me).

3 Likes