I use popup editing to create/update the rows in the datagrid and I want to ask a confirmation if the user closes the popup (using the close button or the cancel buttom) when some field has changed.
I subscribed to the editorOptions.onValueChanged event to update my isDirty flag and I subscribed to onRowInserting ad onRowUpdating to clear the isDirty flag and allow the popup to close without confirmation.
My problem is that I'm using the onPopupHiding event to ask the confirmation, because I couldn't find any suitable event in Datagrid or Form and I'm afraid it gets fired too late.
In most cases it works, but there is a situation which I can't solve: if I open a popup, change some fields, cancel, answer No to keep the popup open I loose all the changes. They are still visible on the screen, but they're gone from the form data: if I click save the onRowUpdating/onRowInserting event is not raised and no change is recorded in the datagrid and if I change another field and click save, this will be the only one updated; the changes made before Canceling are gone.
Is there any other event that I can use instead of onPopupHiding to keep the changes? Is there a way to subscribe to the click event of the Cancel button and the Close button of the Popup?
function onEditorPreparing(e) {
if (e.parentType === "dataRow") {
if (e.dataField === "MessageBody") {
e.editorName = "dxTextArea";
}
e.editorOptions.onInitialized = function (args) {
editors[e.dataField] = args.component;
};
e.editorOptions.onValueChanged = function (args) {
isDirty = true;
e.setValue(args.value);
};
}
}
function onRowInserting(e) {
isDirty = false;
}
function onRowUpdating(e) {
isDirty = false;
}
function onPopupHiding(e) {
if (isDirty && confirm("Vuoi abbandonare le modifiche?") === false)
e.cancel = true;
}
Thanks
Stefano
Hello Stefano,
The cause of the issue is unclear to me. I suggest that you check the dxDataGrid - How to customize buttons in the Popup Edit Form ticket where Nikolai demonstrated the approach of how to handle the popup form's Cancel and Save buttons. I believe that this approach is easier to implement. If it is not suitable for your task, please prepare a simple project illustrating the problem so that we can give it a closer look. We will do our best to find an appropriate solution for you.
Thanks,
Alisher