Leave without saving warning in custom component

default discord avatar
2 months ago

Hi all,

I've made an UI field (custom component) that manage changes of others fields.

I noticed that if I change from my custom component then move page, this unsaved warning was not appeared.

Could anyone explain what is the logic behind it? I mean to trigger that warning

Leave without saving warning in custom component

Found myself way to trigger

add this to the component's

import {useForm} from "payload/components/forms";
const {setModified} = useForm()

then in event to handle change

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


    Connect with the Payload Community on Discord



    Can't find what you're looking for?

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