Commits

Basil Mironenko committed ca9eaeb Draft

Fixed HTML field IDs in FileBrowser.clear(). Also, enable the "clear" link if a file has been submitted but not yet saved.

Comments (0)

Files changed (3)

filebrowser_safe/static/filebrowser/js/AddFileBrowser.js

         }
     },
     clear: function(id) {
-        var id2=String(id).replace(/\-/g,"____").split(".").join("___");
-        $('#help_'+id2+', #clear_'+id2).hide();
-        $('#'+id2).val('');
+        $('#help_'+id+', #clear_'+id).hide();
+        $('#'+id).val('');
     }
 }
 

filebrowser_safe/static/filebrowser/js/FB_FileBrowseField.js

     var preview_id = 'image_' + input_id;
     var link_id = 'link_' + input_id;
     var help_id = 'help_' + input_id;
+    var clear_id = 'clear_' + input_id;
     input = opener.document.getElementById(input_id);
     preview = opener.document.getElementById(preview_id);
     link = opener.document.getElementById(link_id);
     help = opener.document.getElementById(help_id);
+    clear = opener.document.getElementById(clear_id);
+
     // set new value for input field
     input.value = FileURL;
 
+    // enable the clear "button"
+    $(clear).css("display", "inline");
+
     if (ThumbURL && FileType != "") {
         // selected file is an image and thumbnail is available:
         // display the preview-image (thumbnail)

filebrowser_safe/templates/filebrowser/custom_field.html

 </p>
 {% endifequal %}
 {% if not self.is_required %}
-    {% if value %}
-    <p class="help mezz-fb-clear" id="clear_{{ final_attrs.id }}" style="display:inline; margin:0 10px;">
+    <p class="help mezz-fb-clear" id="clear_{{ final_attrs.id }}" style="display:{% if value %}inline{% else %}none{% endif %}; margin:0 10px;">
         <a href="javascript:FileBrowser.clear('{{ final_attrs.id }}');">{% trans "Clear" %}</a>
     </p>
-    {% endif %}
 {% endif %}
 {% if final_attrs.DEBUG %}
 <p>