简体   繁体   English

jQuery UI删除后的多个对话框的位置?

[英]Jquery ui multiple dialogs positioning after deletion?

I am using jquery ui Dialog box to create multiple notes in my Web Application. 我正在使用jQuery ui对话框在Web应用程序中创建多个注释。 So there is a add-note button which clicks to open a note (dialog box at center). 因此,有一个添加笔记按钮,单击该按钮可以打开一个笔记(位于中心的对话框)。

User can open multiple notes (dialogs) together and fill content save, delete, etc on each. 用户可以一起打开多个注释(对话框),并在每个注释上填充,删除等内容。

Problem arises when multiple notes are opened and I start deleting some randomly. 打开多个便笺并开始随机删除一些便笺时出现问题。 So on deletion the positioning of the opened dialog gets affected. 因此,在删除时,打开的对话框的位置会受到影响。 The opened dialogs after deletion of any start moving upwards on the screen. 删除任何内容后打开的对话框开始在屏幕上向上移动。

I have been trying to solve this from quite some time. 我一直在努力解决这一问题。 Plz help. 请帮助。

My JS : 我的JS

function createNote(note, noteContent, newNote){

        var noteDiv = $('<div> <textarea class="note-textarea" style="width:100%;background-color:#D3D3D3;"></textarea> </div>');

        noteDiv.clone(true).attr("id", noteId)
        .dialog({
            modal : false,
            draggable : false,
            resizable : false,
            open: function(){
                $("#"+ noteId).find('textarea').val(noteContent);
                $("#"+ noteId).find('textarea').css({
                    'height': $("#" + noteId).parent().height()
                });

            }, create: function(){

                // Create Title Textfield inside note top bar
                $("<input type = 'text' placeholder='Title' class='note-title'></input>").appendTo($("#"+ noteId).prev(".ui-dialog-titlebar").find('span'));
                $("#"+ noteId).prev(".ui-dialog-titlebar").find('input').val(noteTitle);

                if(!jQuery.isEmptyObject(note)){

                    createLastModifiedSpan($("#"+ noteId), lastModified);               
                }
            },
            buttons : [ {
                text : "Save",
                disabled: true,
                click : function() {

                ......AJAX CALL to SAVE
            }],
            beforeClose: function(event, ui) {

                if(confirm('Are you sure you want to delete this note?')){
                    $.ajax({
                        type: 'POST',
                        url: "/common/deleteNote.action",
                        data:
                        {                   
                            'note.id.operatorId':$('#operatorId').val(),
                            'note.id.noteId':noteId

                        },
                        success: function(data, textStatus, jqXHR){

                            if(data.result == 'success'){
                                alert('Deleted Successfully');
                                numberOfNotesCreated--;
                            }else
                                alert('Error in Deleting. Contact Admin');
                        },
                        error: function(data){
                            alert("Error in DB!");
                        }   
                    });

                }else
                    return false;

            },
            resize: function(event, ui) {alert('dskjfsf')},
            position:[10,100]
        }); 

        $("#"+ noteId).dialog('open');

        $("#" + noteId).parent().draggable()
        .resizable();/*.position({
               my: "center",
               at: "center",
               of: window
            });*/

        //Fire event on Either textarea or note title
        $("#"+ noteId).find('.note-textarea')
        .add($("#"+ noteId).prev('.ui-dialog-titlebar').find('.note-title')).keydown(function(event) {

            if($(this).val() != '') {
                toggleSaveButton($( "#" + noteId ), "enable");
            }
        });

        if(newNote){
            elementCount++;
            numberOfNotesCreated++;
        }
        prevNoteId = noteId;

    }

EDIT : If I add notes in sequence say 1, 2, 3, 4 and start deleting from the recently added like 4, 3, 2.. the positiong does not give a problem, however when I start deleting randomly 2, 1.. then the other notes postioning gets disturbed. 编辑 :如果我按顺序添加注释,说1、2、3、4并开始从最近添加的注释中删除,例如4、3、2。positiong不会出现问题,但是当我开始随机删除2、1,..然后其他音符的​​位置就会受到干扰。

Found this on the jquery form which solved my problem : 在解决我的问题的jquery表单上找到了这个:

https://forum.jquery.com/topic/bug-when-closing-one-dialog-within-multiple-stacked-dialogs https://forum.jquery.com/topic/bug-when-closing-one-dialog-within-multiple-stacked-dialogs

Put this in close function of the dialog: 将其放在对话框的关闭功能中:

var widget = $(this).dialog("widget"), height = widget.height();
widget
    .nextAll(".ui-dialog").not(widget.get(0))
    .each(function() { var t = $(this); t.css("top", (parseInt(t.css("top")) + height) + "px"); });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM