Check if a record needs a save

Hello,

How does the save button on an edit page know when to appear? This is the property I would like access to as well.

Thanks

Like 0

Like

3 comments
Best reply

You can use this to determine if the record needs saving (if the save button is showing)

if (this.get("ShowSaveButton")) {
    // needs saving
}

Ryan

You can use this to determine if the record needs saving (if the save button is showing)

if (this.get("ShowSaveButton")) {
    // needs saving
}

Ryan

Ryan Farley,

Hi Ryan,

Any possibilities in freedom UI for this?

Geeviniy Vazavan,

For Freedom UI you can check the attribute “HasUnsavedData”. This will tell you if the page needs to be saved.

const needsSave = await request.$context.HasUnsavedData;
if (needsSave) {
    // do somehting
}

Additionally, you can listen for changes to this attribute as well to respond to when it changes:

{
    request: "crt.HandleViewModelAttributeChangeRequest",
    handler: async (request, next) => {
        if (request.attributeName === "HasUnsavedData" && request.value) {
            // the form needs saving, request.value will be true if needs saving
        }
        return next?.handle(request);
    }
}

Ryan

Show all comments