Base solution for your next web application
Open Closed

Controller validation and abp.message.confirm #3348


User avatar
0
PhilWynn created

Hi,

I am using Controller Validation to validate against certain errors. The code has worked fine until I use abp.message.confirm in the save method:

function _attachCloseEvent() {
            _modalManager.getModal().find('.issue-close').click(function (e) {
                e.preventDefault();
                if (!_closeIssueForm.valid()) {
                    return;
                }
                //abp.message.confirm(
                //    app.localize('IssueCloseWarningMessage'),
                //    function (isConfirmed) {
                //        if (isConfirmed) {                            
                            _modalManager.setBusy(true);
                            var issue = _closeIssueForm.serializeFormToObject();
                            abp.ajax({
                                url: abp.appPath + 'Mpa/Issues/CloseIssue',
                                data: JSON.stringify({
                                    issueOutput: issue
                                }),
                                success: function () {                                    
                                    abp.notify.success(app.localize('IssueSuccessfullyClosed'));
                                    _modalManager.close();
                                    abp.event.trigger('app.itemSaved');
                                },
                                always: (function() {
                                    _modalManager.setBusy(false);
                                })
                            });
                    //    }
                    //}
                //);
            });
        }

When confirm is not enabled (as above) things work fine. When I enable confirm, the validation dialog box is not displayed.

Cheers, Phil


7 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Your code seems correct. Do you have any javascript error on console ?

    Thanks.

  • User Avatar
    0
    PhilWynn created

    Yes, the validation error appears in the console as expected. No javascript errors are reported. Another interesting thing to note is when I apply the following error handler:

    function _attachCloseEvent() {
                _modalManager.getModal().find('.issue-close').click(function (e) {
                    e.preventDefault();
                    if (!_closeIssueForm.valid()) {
                        return;
                    }
                    abp.message.confirm(
                        app.localize('IssueCloseWarningMessage'),
                        function (isConfirmed) {
                            if (isConfirmed) {                            
                                _modalManager.setBusy(true);
                                var issue = _closeIssueForm.serializeFormToObject();
                                abp.ajax({
                                    url: abp.appPath + 'Mpa/Issues/CloseIssue',
                                    data: JSON.stringify({
                                        issueOutput: issue
                                    }),
                                    success: function () {                                    
                                        abp.notify.success(app.localize('IssueSuccessfullyClosed'));
                                        _modalManager.close();
                                        abp.event.trigger('app.itemSaved');
                                    },
                                    error: function () {
                                        alert('error');
                                    },
                                    always: (function() {
                                        _modalManager.setBusy(false);
                                    })
                                });
                            }
                        }
                    );
                });
            }
    

    In this case, the validation dialog appear correctly while the alert box is shown, but when I dismiss the alert box the validation dialog disappears.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @PhilWynn,

    If you can send your project to <a href="mailto:[email protected]">[email protected]</a>, we can take a look at it. It will be easier to find your problem like that.

    Thanks.

  • User Avatar
    0
    PhilWynn created

    Hi,

    This issue is very easy to reproduce on the initial az code, e.g. creating a User:

    • Remove the 'required' attribute from a field in _CreateOrEditModal.cshtml
    • Fill in the form, leaving this field empty
    • On save, validation message comes from server
    • Now edit _CreateOrEditModal.js 'save' so that the call to userService uses abp.message.confirm
    • On save, no validation message from the server
  • User Avatar
    0
    PhilWynn created

    Hi,

    Just wondering if you have been able to look into this yet?

  • User Avatar
    0
    PhilWynn created

    Hi,

    I could really do with an answer on this issue. Please could you let me know if there is a way around this.

    Thank you

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Sorry for the late response, we were dealing with v4.1 and somehow missed your email. I reproducet the problem and it seems like it is related to sweet alert. Server response is returned before confirmation sweet alert dialog is closed and this problem happens. For a temporary solution you can change your call like this and it will work.

    abp.message.confirm('are you sure ?',function(isConfirmed) {
        if (isConfirmed) {
            setTimeout(function() {
               //ajax call here
            },100);
        }
    });
    

    We will try to find a better solution to this.

    Thanks