Close drawer on relationship save

default discord avatar
Martin R
8 months ago
7

1. log in to

https://demo.payloadcms.com/admin

2. Navigate to posts


3. Create a new category by clicking on the +


4. Fill out the Name


5. Click Save


6. Click Save


7. Click Save



How do I close the drawer in step 5 on save click?



Duplicates are created with no indication or warning. According to the payload team, it's not a bug, but a feature, which makes some sense. The solution was to set unique to true, preventing duplication.



A sane default should not allow for duplicates; for example, Items are created behind the scene, and it breaks the default duplication feature in the primary collection. It's then necessary to create a hook to override the unique field. Maybe the duplication feature should be disabled by default? Or should the drawer close on save?



Thak you for all your great work; it is much appreciated!


Kind Regards


Martin



Can I solve this by creating a custom relationship component? My doubt about the custom relationship component is that PayloadCMS changes fast and breaks the custom components.



Can I rely on custom components, or is payload customisation of existing components, not a safe option?

  • discord user avatar
    jacobsfletch
    Payload Team
    7 months ago

    Totally, this makes perfect sense. The current behavior is to keep the drawer open for continued editing but I can see how creating duplicates might be unexpected. Your solution is the correct one, you just need to set

    unique: true

    on your category slug and let the API error prevent the update. This didn't work for you? You shouldn't have to create a custom component for this, that would be a nightmare although we're actively overhauling our component library right now. You can track the progress here

    https://github.com/payloadcms/payload/discussions/293
  • default discord avatar
    Martin R
    7 months ago

    This didn't work for you? no, unique is not an option case it's multi tenant, I could manually prevent a unique check.

  • discord user avatar
    jacobsfletch
    Payload Team
    7 months ago

    Ok in this case you'd just want to write your own validation function to ensure uniqueness within the tenant.

  • default discord avatar
    seth
    7 months ago

    +1 to this, could be addressed with two distinct buttons "Save" and "Save & Close" (my hunch is the latter is the more common use case)

  • default discord avatar
    Martin R
    7 months ago

    out of curiosity, what is the use case for saving multiple relations without closing the drawer? like add?

  • discord user avatar
    jacobsfletch
    Payload Team
    7 months ago

    The general use case for this is to allow continued editing of the document after save, just like top-level documents. If this has high enough demand, though, the UX here can certainly be revisited. "Save & Close" is as action I could see the need for so it may be worth exploring this further in design.

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.