Can you use Hooks with _owner field key?

Someone please help!

I’m trying to use the beforeUpdate hook to stop members joining a collection twice, whereby it checks to see if the owner ID is already in the collection.

Firstly, is this the correct hook or should I use beforeInsert, because there is a possibility where the member hasn’t already submitted to the collection so there’s nothing to update.

Secondly I’m just checking the use of owner field (as in the standard wix field ‘owner’), as field name is owner but field key is _owner. Should I put _owner as the field value in the js-file?

Been hitting a brick wall for two days now, someone please help.

to stop them from joining use beforeInsert. I assume you mean signed up users though. If it’s during the signup process, it’s a bit more tricky.
yes, _owner is the field key

Hi Plon,

It’s a collection for members to receive qualifications, I used a boolean field connected to a tick box (already selected) and a submit button for members to add themselves to the collection. Once in the collection admin will add the qualifications.

What I want is for a way to stop that signed in member (_owner) creating additional entries to that collection. But there’s a few things I’m not clear on.

  1. Creating the hook - Should I do this by going to the collection’s data manager and select the hook function or go to backend in the side menu and add new js.file? If you do the former it populates the js.file automatically named data.js.

  2. What code do I need for the beforeInsert function as I’ve seen a few variations in other threads. Is there an example anywhere you know of based on what I’ve explained. Also I paste the code in the js.data file not add the code to the specific page right? There’s just a few gray areas putting all this together!

  3. Lastly, and this might sound obvious newby territory but when inputting the owner field in the code I should put _owner for the field name and value, is that sounding right?