jQueryのUIタブとダイアログ - ダイアログのプラグインに基づいて確認して切り替えタブを確認するには?

StackOverflow https://stackoverflow.com/questions/2631064

質問

そうでは、目標は、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;
    }
});
役に立ちましたか?

解決

あなたの問題の原因は、window.confirmがブロックしているとjQuery UIのダイアログではないということです。あなたは異なってコードを構造化することにより、この問題を回避することができます。ここでは多くの可能なアプローチの一つです。

$(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');
             }
        }
    });
});
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top