Commits

Chris Perkins committed d344689

form toggling works in IE now.

  • Participants
  • Parent commits 85a615a

Comments (0)

Files changed (1)

File src/tgext/subform/static/javascript/select_field_with_add.js

-//holds a reference to all available subform caches, which is used to update related subforms.
-var subformCache = {};
-
 /*
 toggleSubForm
 
 
 */
 var toggleSubForm = function(id){
-    var i,c;
+    var i, c, el, wrapper;
     var q = dojo.query('#'+id+'_opener');
+
     if (q.length < 1){
         return;
     }
-    var el = q[0];
-    var wrapper = dojo.query('#'+id+'_wrapper')[0];
+
+    el = q[0];
+    wrapper = dojo.query('#'+id+'_wrapper')[0];
     
 
-    for (i=0; i<el.classList.length; i++){
-        c = el.classList[i];
-        if (c === 'subform-opener-open'){
-            q.removeClass('subform-opener-open');
-            q.addClass('subform-opener-closed');
-            wrapper.style.display='none';
-            return;
-        }
+    if (el.className.indexOf('subform-opener-open')>0){
+        el.className = el.className.replace('subform-opener-open', 'subform-opener-close');
+        wrapper.style.display='none';
+        return;
+    }
+
+    if (el.className.indexOf('subform-opener-closed')>0){
+       el.className = el.className+' subform-opener-open';
+    }
+    else{
+        el.className = el.className.replace('subform-opener-closed', 'subform-opener-open');
     }
-    q.removeClass('subform-opener-closed');
-    q.addClass('subform-opener-open');
     wrapper.style.display='block';
 
 };
 
+//holds a reference to all available subform caches, which is used to update related subforms.
+var subformCache = {};
+
 /*
 The contructor for the SubForm class.
 
 
 */
 SubForm.prototype.addOption = function(item, selected){
- 
+
     var i;
-    
+
     var wrapper = dojo.query('#'+this.config.form_id+'_wrapper')[0];
-    
+
     var pk_names = this.config.pk_names;
     var display_field_name = this.config.display_field_name;
-    
+
     var pk_values = [];
-    
+
     for(i=0; i<pk_names.length; i++){
         pk_values.push(item[pk_names[i]]);
     }
-    
+
     var value = pk_values.join('/');
     var name = item[display_field_name];
-    
+
     //find the select field that share's the wrapper's (great-)*grandparent
-    var selectfield = dojo.query('select#'+this.config.subtype)[0]
-    
+    var selectfield = dojo.query('select#'+this.config.subtype)[0];
+
     var option = dojo.create('option');
     option.value = value;
     option.innerHTML = name;
 SubForm.updateRelatedSubForms
 
 Updates the subforms that are marked as related when the subforms are initialized.
-This adds the new record to the select field so that it can be selected for the 
+This adds the new record to the select field so that it can be selected for the
 main form's update.
 
 */
     var field_name;
     var field;
     var fields = this.getFields();
-    
+
     for (field_name in fields){
         if (fields.hasOwnProperty(field_name)){
             field = fields[field_name];
 */
 SubForm.prototype.submit = function(){
     var config = this.config;
-    
+
     var url = "./";
     if ((config!==undefined)&&(config.url !== undefined)){
         url = config.url;
     }
     var values = this.getValues();
-    
+
     values.__subtype = config.subtype;
     values._method = 'subtype_post';
-    
+
     var subform = this;
 
     dojo.xhrPost( {
         // The following URL must match that used to test the server.
-        url: url, 
+        url: url,
         handleAs: "json",
         content: values,
         timeout: 5000, // Time in milliseconds
         preventCache: true,
 
         // The LOAD function will be called on a successful response.
-        load: function(response, ioArgs) { 
+        load: function(response, ioArgs) {
             subform.clearValues();
             toggleSubForm(subform.config.form_id);
             subform.addOption(response, true);
             subform.updateRelatedSubForms(response);
         }//,
-        /*error: function(response, ioArgs) { 
+        /*error: function(response, ioArgs) {
             console.error("HTTP status code: ", ioArgs.xhr.status);
             return false;
         }*/
 /*
 SubForm.getFields
 
-Get's all of the subforms input fields, returning them as a dictionary 
+Get's all of the subforms input fields, returning them as a dictionary
 indexed by the name associated with the input.
 
 */
     var subform = dojo.query('div[id="'+form_id+'_wrapper"]')[0];
 
     var fields = {};
-    
+
     var subfields = subform.getElementsByTagName('input');
     for (i=0; i<subfields.length; i++){
         field = subfields[i];
     var fieldValues = {};
     var fields = this.getFields();
     var field_name, field;
-    
+
     for (field_name in fields){
         if (fields.hasOwnProperty(field_name)){
             field = fields[field_name];
     var fields = this.getFields();
 
     var subform = this;
-    
+
     fieldValues._method = 'validate';
     fieldValues.__subtype = config.subtype;
 
     dojo.xhrGet( {
         // The following URL must match that used to test the server.
-        url: url, 
+        url: url,
         handleAs: "json",
         // form: form_id,
         content: fieldValues,
         preventCache: true,
 
         // The LOAD function will be called on a successful response.
-        load: function(response, ioArgs) { 
+        load: function(response, ioArgs) {
             var errors = response;
             var key;
             for (key in fields){
                         el.innerHTML = error;
                     }
                 }
-                
+
             }
             //there are no errors
             if (Object.keys(errors).length === 0){
             return false;
         },
         // The ERROR function will be called in an error case.
-        error: function(response, ioArgs) { 
+        error: function(response, ioArgs) {
             console.error("HTTP status code: ", ioArgs.xhr.status);
             //return response;
             return false;