0

Problem:

I'm required to call custom function ValidateNumericInputBox, which will return focus to a text field which will cause an infinite loop.

I originally had buttons that would perform the lookup, but after going over the page with our end users it was decide to have lookups/validations performed on exit of the text field. So I need to find a way to kill this infinite loop that is created from conflicting code. The weird part is that this doesn't occur in Chrome or Firefox, only IE.

Original Problem:

IE freezes (infinite loop) when I have a jquery modal dialog box open for an error. In the IE developer tools I can see it looping. This does not occur in Firefox and Chrome.

Code:

$(DivID).dialog({ 
  width:375, 
  height:550, 
  modal:true, 
  closeOnEscape:true,  
  buttons: [ { text: "Ok", click: function() { $( this ).dialog( "close" ); } } ] 
});

From research on SO I read that having this line would help:

close: function(event,ui){},

Issue still occurs when added. This is source:

JQuery dialog freezing on close

Display Dialog Box Code

function DialogBox(Params){ 
 ...
 variables
 ...

 if(arrParams[3])
  errMsg = arrParams[3]; //custom error message

 // CLOSE DIALOG BOX
 if (DivStatus == 'Close'){ 
  $(DivID).hide();
  $(DivID).dialog('close');
 }
 else if(DivStatus === 'Open'){
   ....
   logic for determining err msg
   ....                          

   $(DivID).dialog({ width:375, height:550, modal:false, closeOnEscape:true, focus:    function( event, ui ) {}, buttons: [ { text: "Ok", click: function() { $( this ).dialog( "close" ); } } ] });

}
else{   //  General error message - uncaught error
 if (DivID == '#Div_ErrorMessage')
   {    $(DivID).dialog({ width:375, height:150, modal:true, closeOnEscape:true, close: function(event,ui){},buttons: [ { text: "Ok", click: function() { $( this ).dialog( "close" ); } } ] });    }
 }
}

HTML DIV For Dialog Box

<div id="Div_Wrapper" style="background:#EBEBEB;">
            <div id='Div_LoadingOverlay' class="Div_LoadingOverlay_Relative noPrint"><div class='Div_LoadingOverlay'><br><br><img src='/common/images/misc/loader_01.gif' align='absmiddle' /><br>Loading...</div></div>
            <div id='Div_ErrorMessage' style='display:none;' title='Error Message'>There seems to be something wrong with the form...</div>

Research:

JQuery dialog freezing on close

jquery Ui-dialog and ie8

A lot of issues that I researched are dated <= 2010, and deal with browsers that I don't support. Also are not completely relevant.

Browsers tested

IE 9,10 - does not work

Firefox 18.0.1 - works

Chrome Version 34.0.1847.137 m - works

More test cases:

1) Removed $( this ).dialog( "close" ); in the click function. - Does not work.

2) Brought things back to the basics and copied and pasted the code straight from jquery's website

$( "#dialog-modal" ).dialog({
      height: 140,
      modal: true
    });

Changing of course #dialog-modal to be DivId. - This does not work.

EDIT 0

I just realized this would be useful information and is part of the problem. I perform validation on a text field on the onBlur event. So whenever the user exits the text field validation is performed and if it's invalid input then this dialog box will appear. So what I think is happening after this dialog box pops up it returns focus to the text box and then focus returns back to the dialog box which creates this infinite loop.

EDIT 1

That's exactly it, but it's because I have code that is returning focus to the text field to outline the text field as red. These are user requirements and I can't change them.

This function is called to lookup information and validate the field. If an error is returned from the JSP page then

function someFuncNameLookup(params){
....
//SubmitForm =  ValidateNumericInputBox('#'+ arrParams[0] +' #'+orgType+'^5^0');
// SUBMIT FORM
//if (SubmitForm.length == 0){
if (0 == 0){
 $('#Div_LoadingOverlay').show();
 $.post("/someDirectory/someFileName.jsp", 
   { ID20140411: "LookUp_org|"+ $("#"+orgType).val() + '|' + orgType }, 
    function(ID20140411_LoadDefault_data) { 
       var splitData = ID20140411_LoadDefault_data.split("%");
       var splitString = splitData[1].toString();
       var pairs = splitString.split(",");                                                      if(ID20140411_LoadDefault_data.search('orgLookupError') != -1){
     DialogBox('Div_ErrorMessage^Open^orgLookupError');
     }else{
       displayLookupData(pairs,lookupType);
     }
 });  
}else{
   DialogBox('Div_ErrorMessage^Open^orgLookupError');
}
$('#Div_LoadingOverlay').hide();
}

The ValidateNumericInputBox will return focus to text field that had an error. This is part of a library of code from another group in my company that I am "required" to use. I change the if(0==0) to confirm ValidateNumericInputBox was the reason for my issue . When I have if(0==0) I don't get the infinite loop. What's weird is this only happens in IE.

5
  • How are you triggering the dialog to display? What versions of the jquery libraries are you using? Commented May 23, 2014 at 19:36
  • so... problem solved? Commented May 23, 2014 at 19:37
  • @Jasen jquery-1.9.1.js & jquery-ui-1.10.3 Commented May 27, 2014 at 13:28
  • @pennstatephil Nope. I will have to talk to the other dev group about this. I'm surprised they haven't encountered this problem. I will post a solution once I find it out. Commented May 27, 2014 at 13:30
  • @jasen added section for how I trigger the dialog box. Commented May 27, 2014 at 13:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.