fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2011-12-05 04:16 am

[dw-free] Revamp /update

[commit: http://hg.dwscoalition.org/dw-free/rev/193cb5660dd4]

http://bugs.dwscoalition.org/show_bug.cgi?id=2524

Clean element names to use only valid characters before using them as part
of an id.

Patch by [personal profile] fu.

Files modified:
  • htdocs/js/jquery.tagselector.js
--------------------------------------------------------------------------------
diff -r 573d5fc0fe61 -r 193cb5660dd4 htdocs/js/jquery.tagselector.js
--- a/htdocs/js/jquery.tagselector.js	Mon Dec 05 12:13:23 2011 +0800
+++ b/htdocs/js/jquery.tagselector.js	Mon Dec 05 12:16:50 2011 +0800
@@ -120,6 +120,11 @@
     </div>";
     };
 
+    var _regex = new RegExp("[^a-z0-9]","ig");
+    function _as_attr(tag) {
+        return tag.replace(_regex, "_");
+    }
+
     function _initTags() {
         $("button", $.fn.tagselector.instance.siblings()).attr("disabled", "true");
         $(":input", $.fn.tagselector.instance).attr("disabled", "true");
@@ -135,9 +140,10 @@
         var $tagslist = $("<ul id='tagselector_tags_list'></ul>");
 
         $.each(data, function(index, value) {
+            var attr = _as_attr(value);
             $("<li>").append(
-                $( "<input>", { "type": "checkbox", id: "tagselector_tag_" + value, "value": value, "checked": selected[value] } ),
-                $("<label>", { "for": "tagselector_tag_" + value } ).text(value) )
+                $( "<input>", { "type": "checkbox", id: "tagselector_tag_" + attr, "value": value, "checked": selected[value] } ),
+                $("<label>", { "for": "tagselector_tag_" + attr } ).text(value) )
             .appendTo($tagslist)
         });
 
--------------------------------------------------------------------------------