1

したがって、目標は、UIダイアログプラグインを使用して別のUIタブへの切り替えを確認することです。一般的な確認方法の使用は簡単です。

jQuery("#tabsContainer").tabs({
    select: function(event, ui) {
        return confirm("Some confirmation message...");
    }
});

しかし、ダイアログモーダルボックスを使用して同じ動作を実現する方法は?

私は電話しなければならないと思います:

jQuery("#tabsContainer").tabs("select", ui.index);

「okコールバック」で、しかしこれは私が期待したように機能していません。また、報告されているエラーはありません...

jQuery("#tabsContainer").tabs({
    select: function(event, ui) {
        jQuery("#dialogContainer").dialog({
            buttons: {
                'Ok': function() {
                    jQuery("#tabsContainer").tabs("select", ui.index);
                },
                Cancel: function() { return; }
            }
        });
        return false;
    }
});
4

1 に答える 1

3

問題の原因window.confirmはブロッキングであり、jQueryUIのダイアログはそうではありません。コードを別の方法で構造化することで、これを回避できます。考えられる多くのアプローチの1つを次に示します。

$(function() {
    jQuery('#tabsContainer').tabs({
        select: function(event, ui) {
            // only allow a new tab to be selected if the
            // confirmation dialog is currently open.  if it's
            // not currently open, cancel the switch and show
            // the confirmation dialog.
            if (!jQuery('#dialogContainer').dialog('isOpen')) {
                $('#dialogContainer')
                    .data('tabId', ui.index)
                    .dialog('open');
                return false;
            }
        }
    });

    jQuery('#dialogContainer').dialog({
        autoOpen: false,
        buttons: {
            'Ok': function() {
                 // a new tab must be selected before
                 // the confirmation dialog is closed
                 var tabId = $(this).data('tabId');
                 $('#tabsContainer').tabs('select', tabId);
                 $(this).dialog('close');
             },
             'Cancel': function() {
                 $(this).dialog('close');
             }
        }
    });
});
于 2010-04-13T16:32:53.827 に答える