Why would a 'change' event not get triggered?

I’m trying to listen to the ‘change’ event for an input, but it doesn’t seem to be triggering; I have a ‘print’ statement that isn’t getting printed. What could be causing this?

To experiment, I tried adding the same function to the other events: the ‘focus’ event seems to work, and I think also the ‘show’ event, but not the ‘lost_focus’ event.

Can you provide an example app to demonstrate the issue?

1 Like

@alcampopiano
https://anvil.works/build#clone:JUCK7DU2676DY2ID=UAQQKKGHH6G7AZWKSORIELGU

It’s the ‘EditProfile’ form, the ‘Company’ card, the ‘Name’ field, which should call the ‘handle_company_name_change’ function.

Can you prepare a simpler example that demonstrates only that issue? Your app has dependencies and related code that prevents me from running it. I am looking at the code though but I’d like to be able to run something that is close to what you have.

In my basic testing in another app, the change event seems to work as expected (event with write back enabled). You can see that here:
https://anvil.works/build#clone:DM6FNDQNGKGS4VF3=HRET3SBQIADTCNNPSNTFHJ3B

@alcampopiano Can you explain what ‘related code’ would prevent you from running it? I’m new to Anvil so I’m just not familiar with this. I thought that the dependencies would be copied for you in addition to the app, as that seems to be what happened when I copied someone else’s app.

@alcampopiano I figured out the problem: it was the form_validation custom component I had started using, as found here: https://anvil.works/library/form-validation

When I disabled the form_validation's association with the name field, the change event started triggering.

Absolutely. The general idea is that you want to make an example app that anyone can run straight away. It can be easy to forget about dependencies so if you have those, you would have to remove them and the code that relies on them. Otherwise, folks on the forum will have to do a lot more work to get things to run (removing code, etc).

In your app I had to remove dependencies, delete various lines of code from multiple forms (related to dependencies), and set myself up as a user with specific meta-data.

So you would want to make it easier than that for folks to assist.

In any case here is a working example of your app:
https://anvil.works/build#clone:M3MQC5VC6FTFRXR2=E6BIAKNCD4PK4SZYY2NQLJFN

1 Like