don't allow close of editor

don't allow close of editor

montoyammontoyam Posts: 568Questions: 136Answers: 5

I don't want to allow users to close the editor by clicking the background (grey area) or the 'x' in the upper right of the editor window. I think the answer is somewhere in this code: https://editor.datatables.net/examples/api/confirmClose.html

but of course there would be no blur if they don't make any changes.

        var PasswordChangeEditor = new $.fn.dataTable.Editor({
            ajax: 'api/Staff',
            table: '#passChange',
            fields: [
                { label: "New Password", name: "Password" }

            ]
        });

        PasswordChangeEditor.add([
            {
                label: "Type password again:",
                name: "confirmPassword"
            }
        ]);

        var PasswordChangeTable = $('#passChange').DataTable({
            ajax: 'api/Staff',
            columns: [
                { data: "Password" }
            ]
        });

        PasswordChangeEditor.on('preSubmit', function (e, data, action) {
            var password = PasswordChangeEditor.get('Password');
            var password2 = PasswordChangeEditor.get('confirmPassword');
            if (password != password2) {
                alert("Passwords don't match. Please re-type the password.");
                return false;
            } else {
                $.ajax({
                    url: "api/ChangePass?login=" + userNameCookie + '&isReset=0&password=' + password,
                    async: false,
                    type: "POST",
                    data: data
                });
                PasswordChangeEditor.close();
                return false;
            }
        });

I open the editor after an ajax call

                            if (response.Table[0].PasswordReset == 1) {
                                PasswordChangeEditor
                                    .create()
                                    .title('Change Password')
                                    .display(true)
                                    .buttons('Save')
                                ;
                            }

Answers

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    This thread should help, it's asking the same thing.

    Cheers,

    Colin

  • montoyammontoyam Posts: 568Questions: 136Answers: 5

    almost there. thank you for that. :)

    now, how do you get rid of the 'x' at the top right of the editor (just on this editor, not all editors in my project)? I looked here but didn't see anything: https://editor.datatables.net/reference/option/

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    A quick "Inspect" will show that the element has a class of DTED_Lightbox_Close. You can use a little CSS to set that to be display: none;.

    Allan

  • montoyammontoyam Posts: 568Questions: 136Answers: 5
    edited August 2020

    ah, ok. thanks. I wasn't sure if there was something in the Editor initialization where you could turn that off.

This discussion has been closed.