jquery validation plugin, IE7: settings is null or not an object

jquery validation plugin, IE7: settings is null or not an object

Dear all,

I have a problem that I can't seem to find a solution for. 

I have a set of radio buttons that I validate with the jquery validation plugin to make sure that they are selected.I want the user to choose Resit (Yes/No), Standard glh (Yes/No) and then pressing "Finish". An error should be reported if any of them are empty. I dynamically wrap a form tag around the table where the radio buttons are located and then validate that form. This works fine in Firefox and Chrome but not in IE7. I debug the code while using IE 7 and Visual studio says:

 "Microsoft JScript error: 'settings' is null or not an object". It occurs on line 302 in jquery validation plugin 1.6:

  1. function delegate(event) {
    var validator = $.data(this[0].form, "validator");
    validator.settings["on" + event.type] && validator.settings["on" +       event.type].call(validator, this[0] );
    }

I have tried this with validation plugin 1.6 and 1.7 and jquery 1.3.2 and 1.4.2.  The combination 1.6, 1.3.2 and 1.7 , 1.4.2 both report the problem.

I read that there were compatibility issues with the validation plugin and jquery 1.4 (see link below) so that's why I tried with 1.6 and jquery 1.3.2. ( http://forum.jquery.com/topic/validate-compatability-with-jquery-1-4)

I don't know what's causing it and I would appreciate and help in solving this. I include sample code below.

Thank you,

/S
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en">
  3. <head>    
  4. <script type="text/javascript" src="jquery.js"></script>
  5. <script type="text/javascript" src="jquery.validate.js"></script>
  6. <script type="text/javascript">
  7. $(document).ready(function () {


  8.    $('#finish').click(function(){
  9.        alert("hej");
  10.     $("<div id='jserrorsummary'></div>").appendTo("#finish-element"); // I use this div to display the errors

  11.     // Get the table and insert the table into a temporary form tag
  12.     // Evaluate the temporary form and bring all the error msg into
  13.     // an alert box. jquery validation plugin works with a form tag only

  14.     // Wrap the fields in a form tag. Validate the form and remove the form tag afterwards
  15.     if ( $("#aoss").length > 0)  {
  16.         $("#aoss").wrap("<form id='tmpform'> </form>");
  17.     }
  18.     else{
  19.         // table is empty. just continue to the login page
  20.         alert("login");
  21.     }

  22.     var validator = $("#tmpform").validate({
  23.            submitHandler: function(data) {
  24.    },

  25.         // I use this to move the error messages to the top of the form
  26.         // to make it easier to read
  27.         showErrors: function(errorMap, errorList) {

  28.             var fieldnames = {};
  29.             fieldnames.hrs_per_week = "h &nbsp; w";
  30.             fieldnames.no_of_weeks = "w &nbsp; y";

  31.             var msg = "<div class='errorheading'>Your form contains "
  32.                                    + this.numberOfInvalids();

  33.                switch(this.numberOfInvalids() ){
  34.                    case '0':
  35.                      msg += " error";
  36.                    break;

  37.                     case "1":
  38.                         msg += " error, see details below.";
  39.                         break;
  40.                    default:
  41.                        msg += " errors, see details below.";
  42.                        break;
  43.                }              
  44.                  var errorText = "";
  45.                  var n = 0;

  46.                  // Create un <ul> with the errors in it.
  47.                  errorText = errorText + "<ul>";
  48.                  while (n < errorList.length)
  49.                  {
  50.                      var errorObj = errorList[n++];

  51.                     // Wrap this in an <li>
  52.                      errorText +=  "<li>";
  53.                      errorText += "<span class='errorlabel'>" + errorObj.element.name + "</span>:" + "<span class='errormessage'>"+errorObj.message+"</span>";                    
  54.                      errorText +=  "</li>";
  55.                  }
  56.                  errorText +=  "</ul>";
  57.                                   
  58.                 msg += errorText;
  59.                 msg += "</div>";
  60.        $("#jserrorsummary").html(msg);
  61. }
  62.     });

  63.     // Execute the validation
  64.     var isValid = $("#tmpform").valid();

  65.     if (isValid == true){
  66.          var arr = {};
  67.         // add the values of radio buttons and check boxes
  68.         $("input:checked").each(function(){
  69.    // Store values with ajax
  70.         });

  71.         // Textboxes
  72.         // Get all textboxes that are inside #tmpform and are not disabled
  73.         $("#tmpform input:text:not([disabled])").each(function(){
  74.      // Store values with ajax
  75.         });
  76.     }

  77.     // Remove the temporary form tag from the dom
  78.      $("#aoss").unwrap();

  79.   // Run through the errors and add a red border around the element (adding the
  80.   // class "error"). If not remove the class
  81.     var errorList = validator.errorList;
  82.     $("input").each(function(){
  83.         var elementName = $(this).attr("name");
  84.         var isError = false;
  85.         var n = 0;

  86.         // Compare the element name against the error
  87.         while (n < errorList.length)
  88.         {
  89.             var errorObj = errorList[n++];
  90.             var errorElementName = errorObj.element.name;
  91.             if (elementName == errorElementName)
  92.                 {
  93.                    isError = true;
  94.                    break;
  95.                 }
  96.         }
  97.         // Create a red border around the elment if it is an error. I use a
  98.         // pre-created <span> for that
  99.         if (isError == true){
  100.             $("[name='"+elementName+"-borderarounderror']").each(function(){
  101.                 $(this).addClass("borderarounderror");
  102.             });
  103.         }
  104.         else{
  105.             // Remove the red border
  106.             $("[name='"+elementName+"-borderarounderror']").each(function(){
  107.                 $(this).removeClass("borderarounderror");
  108.             });
  109.         }

  110.     });
  111.    }); // click()
  112. });
  113. </script>
  114. </head>
  115. <body>
  116. <div id="content">
  117. <button name="finish" id="finish" type="button">Finish</button> </div>
  118.     <div id="unitsAttached"><table id="aoss"><tbody><tr><th>Product code</th><th>List code</th><th>Version code</th><th>List code</th><th>Description</th><th>Resit</th><th>standard GLH</th></tr><tr><td>SHB2312CNP</td><td>A11</td><td>SHB2312CNU</td><td>A11</td><td id="description_SHB2312CNUA11">Donald Duck 3in</td><td><span id="resit-SHB2312CNU-borderarounderror" name="resit[SHB2312CNU]-borderarounderror"> <input id="resit-SHB2312CNU-1" name="resit[SHB2312CNU]" value="1" class="required" type="radio">Yes
  119.                                 <input id="resit-SHB2312CNU-0" name="resit[SHB2312CNU]" value="0" class="required" type="radio">No </span></td><td><span id="glh-SHB2312CNU-borderarounderror" name="glh[SHB2312CNU]-borderarounderror"><input id="glh-SHB2312CNU-1" name="glh[SHB2312CNU]" value="1" class="required" type="radio"> Yes  
  120.   <input id="glh-SHB2312CNU-0" name="glh[SHB2312CNU]" value="0" type="radio">No</span>       
  121.   </td></tr></tbody></table></div>
  122.     
  123. </body></html>