Hooks not being called

No hooks are being called on my site. Example:

export function CoachInfo_beforeUpdate(item, context) {
item.fullName = ${item.firstName} ${item.lastName};
return item;
}

The record gets updated in preview mode. All fields get updated when submitted from the page, except fullName remains the same. Any ideas?

https://venturamarinersinhouse.com/

Edited: corrected what items update and don’t

Hi,
The other fields in the record are being updated? or is it only the fullName that doesn’t update correctly?
You can use console.log to check if the hook is being called. check out this post

Hi,

Ok, that was a typo. All fields are being updated, except fullName, which remains unchanged. I’ve tried console.log, but didn’t get any messages.

Thanks!

You have your dataset mode set to read-only:


This prevents you from writing to the fullName field.

Yisreal,

That dataset might be from a different page. There are other pages where the permissions allow for writing, and the records in the collection update. Everything except for the field in the hook.

I’m replying from my phone right now, so it’s hard to give the exact page.

Thanks!

This page:


Has this dataset:

And for example, one of the text fields is:

The submit button is configured:


That works. All fields on the page update correctly in the collection. Except the hook is not called, and that last field doesn’t change.

Hi,

I cloned your site so I could play with it without interfering with your work, but I haven’t been able to figure out how to register/login/whatever to your site. I’ve got part of it, but apparently not enough for the input fields on the CoachInfo page to be enabled.

You might have an issue with permissions on the collection. This is what I see:


I would suggest trying “Form Submission” to at least see if that helps.

Let us know what we need to get the site working so we can help you.

Yisrael

Hi Yisreal,

Applogies for the delay getting back to you, it’s been a busy day. Also, applogies for the state of some of the code, I have been experimenting for a few days to get this working. (Just for reference, I am a senior developer with a wide variety of experience.)

Could you grab a fresh copy? I cleaned up a few things to make it easier for you to see what is going on.

The idea is that coaches need to log in, upload certifications, practice plans, and keep their contact information up-to-date. To that end, I implemented and modified Velo Tutorial: Building Your Own Members Area | Help Center | Wix.com. To track who submits certifications and plans, I need a validated user name, which doesn’t seem to be readily available from wix-users api. Since names, emails, etc. can change, it seems best to normalize the data with a unique index value.

There is beforeInsert hook that created a unique integer Id (in column pk). Since numerics cannot be used as indicies, that number is copied to the text field Title. That was working for a while. It stopped working as some point, but I don’t exactly when. Otherwise I would revert the last change to get it back. The beforeInsert hook is in data.js. This hook is not being called either.

With that said, to get it to the point where the beforeUpdate should fire, do this:

  1. Make yourself a Site Member

  2. Clear out data in CoachInfo collection.

  3. Preview from: COACHES >> Coach list

  4. Click My Info

  5. It will appear nothing happened, but there will be messages in the console log. (beforeInsert should have fired.)

  6. Close Preview

  7. Add a unique index in the collection for Title and pk (e.g.: 1) for your record

  8. Preview from: COACHES >> Coach List

  9. You should see default information

  10. Click the Name column (note name is not updating, unless beforeUpdate fired on your copy)

  11. Change first, last, whatever.

  12. Click submit

  13. Note: the information you changed was updated, fullName was not.

Approved members need to read from this collection, and modify their own data. Since Form Submission only allows Admin to read and edit the data, I’m not sure how that would help.

This is an odd one, thanks for your help getting this straight.

Any suggestions yet? Our development is blocked when we cannot use hooks at all.

I’m having the same issues. Did you get your hooks to work?

Hi Brett,

Nothing has happened that isn’t above. It’s frustrating not to be able to use such a basic and critical feature.

As a workaround, I had to modify values on the dataset on every page . That was painful to implement, and it’s a maintainance nightmare. It will only work as the data is being submitted, but the asynchronous nature of those submits requires heavy workarounds.

I’ve spent 3 days on this issue thinking it was me. Wix says no one else has raised this issue. However, I’m starting to feel there is something wrong. I love Wix, but this feature would definitely make life easier.

As you see, the issue was raised a month and a half ago. We missed some important deadlines because of this problem.

Actually, I started with a trouble ticket but they sent me here instead. I purposely did not start with the forums because I have enough software experience to know the problem is not with my code. Not that I write perfect code, but I exhausted every possibility trying to solve the problem myself. Trust me when I say I have a lot of computer experience.

Graphically, Wix is nice. I’m used to working with a few hundred database tables, and it’s database features feel primitive and limiting to me. More like SharePoint Lists or Excel at it’s simplest.

Any response yet?

I sent an email to support and referenced your thread, plus this one: https://www.wix.com/code/home/forum/questions-answers/data-hooks-don-t-seem-to-work-anymore

I also started this new thread: https://www.wix.com/code/home/forum/questions-answers/none-of-my-hooks-seem-to-work

It seems like when I created my first hook awhile back, it worked. Now it doesn’t.

Hi becker2012,
I tried to take a look at your site, but there’s no more logic in data.js
But - there’s still 2 imports in that file:
import wixData from ‘wix-data’;
import wixUser from ‘wix-user’;

Note that the second import is incorrect, you probably meant ‘wix-users’. I guess that’s why the data.js file failed to load in the backend, thus no hooks were running.
Also, to use the users API in the backend you should use the following import instead:
import wixUsers from ‘wix-users-backend’;

Please give it a try and let me know if it works.

Hi Tomer,

I’ll take a look at those later tonight when I have free time. I had to clean out data.js while developing workarounds since we were trying to meet deadlines and blocked by this. Yisreal made a copy, but I don’t have access to that.

Does wix-user-backend give me access to the validated users name? All of this effort is trying to attach a users name to a record so other users can see who uploaded certain files.

Each record has an “_owner” field, with the user ID who inserted this record. Does that help?

That ID is a GUID. We want to display the person’s name.

For example: a coach will upload a practice plan for all the other coaches to see. Everyone needs to know who uploaded the plan, so we need their name displayed with the plan.

Got it. Whenever you have the time, give data hooks another try and let us know if it works this time.

Hi Tomer,

I added a page Testing Hooks and collection TestingHooksCollection . Data.js has the following and nothing else:

export function TestingHooksCollection_beforeInsert(item, context) {
item.hookedField = item.editField;
return item;
}
I was experimenting by removing " import wixUser from ‘wix-user’;" then added it back in, and removed it again. The hook got called once, but I’m not sure exactly when. The hooked field didn’t update on the page, but had when I checked the collection later.

I cannot tweek the existing pages since they work (with workarounds) and are starting to be used.