2012-03-30 9 views
0

Ich habe ein Login-Dialogfeld, das einen Warndialog erstellen kann, wenn der Benutzer nicht alle Felder ausfüllt. Wenn Sie dann auf Escape klicken, wird der Anmeldedialog und nicht der Alarmdialog entfernt.JQuery UI, Dialogfeld erstellt einen Dialog, Hit Escape und das erste Dialogfeld beendet

jquery-1.7.2.js
jQueryUI-1.8.18.js

// alert popup 
function alertMsg(szMsg) 
{ 
    $('#alertText').html(szMsg); 
    $('#alertPopup').dialog('open'); 
} 

$('#alertPopup').dialog({ 
    autoOpen: false, 
    width: 360, 
    resizable: false, 
    modal: true, 
    show: 'scale', 
    hide: 'scale', 
    buttons: { 
     "OK": function() { 
      $(this).dialog("close"); 
     } 
    } 
}); 

// login dialog 
$('#loginDialog').dialog({ 
    open: function() { 
     $('#company').focus(); 
    }, 
    autoOpen: false, 
    width: 360, 
    resizable: false, 
    modal: true, 
    show: 'scale', 
    hide: 'scale', 
    buttons: { 
     "Login": function() { 
      var szCompany = $('#company').val(); 
      var szUser = $('#user').val(); 
      var szPassword = $('#password').val(); 

      if ((/^\s*$/).test(szCompany) || 
          (/^\s*$/).test(szUser) || 
          (/^\s*$/).test(szPassword)) 
      { 
       // this is the alert call that creates the bug 
       alertMsg('You need to fill in Company, User,' + 
           ' and Password'); 
      } 
      else 
      { 
       $(this).dialog("close"); 
       alertMsg(szUser + ' (who works for ' + 
         szCompany + ' and has a secret password of ' + 
         szPassword + ', which is no longer a secret)' + 
         ' check back soon for a real login experience.'); 
      } 
     }, 
     "Cancel": function() { 
      $(this).dialog("close"); 
     } 
    } 
}); 

// handle enter key for login dialog 
$('#loginDialog').find('input').keypress(function(e) { 
    if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) { 
     $(this).parent().parent().parent().parent(). 
      find('.ui-dialog-buttonpane').find('button:first').click(); 
     return false; 
    } 
}); 

Antwort

0

Stellen Sie die "closeOnEscape" Option auf false im Anmeldedialog, und wahr auf dem Alarm-Dialog (es ist wahr, standardmäßig)

+0

wie würde ich dann closeOnEscape wieder in den Login-Dialog aktiviert, nachdem die Warnung geschlossen ist? – TomZ

+0

Nachdem der erste Escape-Befehl den Anmeldedialog entfernt, wird der Alert auch nicht durch einen zweiten Escape-Befehl entfernt. – TomZ

+0

Sie können die CloseOnEscape-Eigenschaft des Anmeldedialogs auf dem Schließen-Ereignishandler des Warnungsdialogs als wahr festlegen. 'code'close: function (event, ui) {$ (" # loginDialog ") .dialog (" option "," closeOnEscape ", false); } 'Code'. –

Verwandte Themen