Does anybody know how to check for unsaved changes in a content item from a property editor? I need to disable some functionality when there are unsaved changes.
I just found out how to do it. I added this code to my button click handler
// get the content item form
var contentForm = angular.element('form[name=contentForm]').scope().contentForm;
// if we have a dirty property show a notification and cancel sending
if (contentForm.$dirty) {
notificationsService.error('You have unsaved changes');
return false;
}
Check if item is dirty in property editor
Does anybody know how to check for unsaved changes in a content item from a property editor? I need to disable some functionality when there are unsaved changes.
Dave
Hi Dave,
with this you can set the state manually in your controller to saved:
It's not exact this what you need, but perhaps this can help you.
Best
Sören
Hi Sören,
I have a property editor with a button in it. Button should be disabled if there are unsaved changes in other properties in the content item.
So i need to know if the item is dirty.
Dave
Hi Dave,
I have not tested it yet, but it should work something like this:
or
Sören
I just found out how to do it. I added this code to my button click handler
Dave
Hi Dave,
great to hear this! And thank you for sharing your code :-)
Sören
Just a comment in relation to this. If you need to set $dirty property to true, you can also use $setDirty()
https://docs.angularjs.org/api/ng/type/form.FormController#$setDirty
So you can use:
or
but this didn't change to dirty state for <ng-form name="propertyForm"> which still had class="ng-pristine ng-valid"
so I had a look at how it is done in the core: https://github.com/umbraco/Umbraco-CMS/blob/2834ccdc2b057619178b3df49aa05ae938faca15/src/Umbraco.Web.UI.Client/src/views/propertyeditors/rte/rte.controller.js
and came up with this:
/Bjarne
Umbraco 8.7.0
I have this where I reuse a Rich text editor..
This return null ...
The same with this:
Can you see what i'm doing wrong..
is working on a reply...