Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Available fields in hooks?

default discord avatar
derosullast year
1

I'm trying to create a generic hook for setting a default value on a field on save, but whenever someone saves the document, the field key is not there when the field has not been filled in by the user.



Would it possible to to get the available fields for a collection while in a hook?



Well, I think I answered my own question. For future reference:



You can get the

req

object in a hook, which includes a

collection

key



So you can access the configured fields like this:

req.collection.config.fields
    Star on GitHub

    Star

    Chat on Discord

    Discord

    online

    Can't find what you're looking for?

    Get dedicated engineering support directly from the Payload team..