Waiting for Dialog to Close

Hi,

I was wondering how can I continue the preCommit function only after the dialog is closed which is opened inside the preCommit function or someway not call commit until dialog is closed.

Kind regards,
Mohamed

Hi Mohamed,

You cannot interact with the user in preCommit() beyond showing notifications. For a legacy API screen, use the approach described in this topic.

For a screen based on API v.7+, use the following approach:

@Inject
private Dialogs dialogs;

@Override
protected OperationResult commitChanges() {
    ValidationErrors validationErrors = validateScreen();
    if (!validationErrors.isEmpty()) {
        ScreenValidation screenValidation = getBeanLocator().get(ScreenValidation.class);
        screenValidation.showValidationErrors(this, validationErrors);

        return OperationResult.fail();
    }

    UnknownOperationResult result = new UnknownOperationResult();

    dialogs.createOptionDialog()
            .withMessage("Are you sure?")
            .withActions(
                    new DialogAction(DialogAction.Type.YES).withHandler(actionPerformedEvent -> {
                        getScreenData().getDataContext().commit();
                        result.success();
                    }),
                    new DialogAction(DialogAction.Type.NO)
            )
            .show();

    return result;
}

As you can see, now it requires copying validation code from the base method. We are going to improve it by introducing a special lifecycle event, see the issue.

Regards,
Konstantin

Hi Konstantin,

Thanks was able to create a custom ok button to close the editor which had the interaction with the user implemented in it instead of the pre commit.

Regards,
Mohamed