Commits

owenmcg  committed 5bc4a45

fixed checklist and radiolist values and add clickable labels

  • Participants
  • Parent commits 5eb2f23

Comments (0)

Files changed (1)

File htraf/jquery.htraf.js

         for(var i = data.length - 1; i >= 0; i--) {
             var row = data[i];
             var label = row[1] === undefined  ? row[0]:row[1];
-            var value = row[0] === null ? row[0]:'';
-            html += '<br/><input type="checkbox" name="'+id+'" value="'+value+'"></input>&nbsp;<span>'+label+'</span>';
+            var value = row[0] === null ? '':row[0];
+            var uniqueID = Math.ceil(100000 * Math.random()) 
+                        + '_' + (new Date).getTime();
+            html += '<br/><input id="'+uniqueID+
+                    '" type="checkbox" name="'+id+'" value="'+value+
+                    '"/>&nbsp;<label for="'+uniqueID+'">'+label+'</label>';
         }
         
         this.element.html(html);
         this._trigger('change');
     },
 
-    _getRow: function() {
-        // We want the value of the checklist to be an array of the values of any checked checkboxes
-        // Not sure how to make this happen
-        var value = [];
-        $(this).find('input:checked').each(function() {
-            value.push($(this).val());
-        });
-        return "'" + value + "'"; 
-    },
-
-    setValue: function(value) {
-        value = value === null ? '':value + '';          
-        this.element._valOrig(value);
+    getValue: function() {
+        var id = this.element.attr('id');
+        // We want the value of the checklist to be the value of 
+        // the selected check box or null if none selected
+        if ( $("#"+id).find('input:checked').length == 0 )
+            return null;
+        else if ( $("#"+id).find('input:checked').length == 1 )
+            return $("#"+id).find('input:checked').attr('value');
+        else // More than one check box selected
+        {
+        // should use and array of values but this is not supported in htsql 1.0
+            //var ckvalue = [];
+            var ckvalue = '{';
+            $("#"+id).find('input:checked').each(function() {
+                //ckvalue.push($(this).attr('value'));
+                ckvalue += $(this).attr('value') +',';
+            });
+            ckvalue = ckvalue.substring(0,ckvalue.length-1) + '}';
+            return ckvalue;
+        }
     },
 
     removeUserSelect: function() {
         for(var i = data.length - 1; i >= 0; i--) {
             var row = data[i];
             var label = row[1] === undefined  ? row[0]:row[1];
-            var value = row[0] === null ? row[0]:'';
-            html += '<br/><input type="radio" name="'+id+'" value="'+value+'"></input>&nbsp;<span>'+label+'</span>';
+            var value = row[0] === null ? '':row[0];
+            var uniqueID = Math.ceil(100000 * Math.random()) 
+                        + '_' + (new Date).getTime();
+            html += '<br/><input id="'+uniqueID+
+                    '" type="radio" name="'+id+'" value="'+value+
+                    '"/>&nbsp;<label for="'+uniqueID+'">'+label+'</label>';
         }
         
         this.element.html(html);
         this._trigger('change');
     },
 
-    _getRow: function() {
-        // We want the value of the radiolist to be the value of the selected radio box or null if none selected
-        // Not sure how to make this happen
-        var value = '';
-        $(this).find('input:checked').each(function() {
-            value.push($(this).val());
-        });
-        return value; 
-    },
-
-    setValue: function(value) {
-        value = value === null ? '':value + '';          
-        this.element._valOrig(value);
+    getValue: function() {
+        var id = this.element.attr('id');
+        // We want the value of the radiolist to be the value of the 
+        // selected radio box or null if none selected
+        if ( $("#"+id).find('input:checked').length == 0 )
+            return null;
+        return $("#"+id).find('input:checked').attr('value');
     },
 
     removeUserSelect: function() {
 	        {
     	         if ( this.isLink(data.meta[0].segment[i].element[j].title) )
     	         {
-    	             query.segment[i].field.push(this.isLink(data.meta[0].segment[i].element[j].title));
+    	             query.segment[i].field.push(
+    	                   this.isLink(data.meta[0].segment[i].element[j].title));
     	             query.segment[i].link.push(true);
     	         }
     	         else
     	         {
-    	             query.segment[i].field.push(data.meta[0].segment[i].element[j].title);
+    	             query.segment[i].field.push(
+    	                               data.meta[0].segment[i].element[j].title);
     	             query.segment[i].link.push(false);
     	         }	            
 	        }
     // see if this is a link column
     makeLink: function(val) 
     {
-        return '<a href="'+val.substring(val.indexOf('|')+1)+'">'+val.substring(0,val.indexOf('|'))+'</a>';
+        return '<a href="'+val.substring(val.indexOf('|')+1)+'">'+
+                           val.substring(0,val.indexOf('|'))+'</a>';
     },
 
     removeUserSelect: function() {
         {
             attrs.seriesColors = this.element.attr('data-colors').split(' ');
             this.assert((attrs.seriesColors instanceof Array),
-                    "Unsupported chart color specification. \n\ndata-colors must be space separated list of colors, either color names or #FFFFFF: \n"
+                    "Unsupported chart color specification. \n\ndata-colors must \
+                    be space separated list of colors, either color names or #FFFFFF: \n"
                     + "red green blue");
         }
         this.assert($.inArray(attrs.type, this.supportedType) != -1,