Skip to content
This repository has been archived by the owner on Mar 5, 2024. It is now read-only.

Commit

Permalink
Transloadit file field: possibility to remove current image
Browse files Browse the repository at this point in the history
The form now displays a "remove" button using the remove glyphicon
before the "Choose File" field to let the user remove a file he
previously uploaded.

The feature would probably benefit from a bit of styling.

Note the uploaded file is not deleted from the server.
  • Loading branch information
François Daoust committed Jun 4, 2013
1 parent 5583866 commit eb99744
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion lib/jsonform.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,14 @@ jsonform.fieldTemplate = function(inner) {
'</div></div>';
};

var fileDisplayTemplate = '<% if (value.type=="image") { %><img class="jsonform-preview" id="jsonformpreview-<%= id %>" src="<%= value.url %>" /><% } else { %><a href="<%= value.url %>"><%= value.name %></a> (<%= Math.ceil(value.size/1024) %>kB)<% } %><br/>';
var fileDisplayTemplate = '<div class="_jsonform-preview">' +
'<% if (value.type=="image") { %>' +
'<img class="jsonform-preview" id="jsonformpreview-<%= id %>" src="<%= value.url %>" />' +
'<% } else { %>' +
'<a href="<%= value.url %>"><%= value.name %></a> (<%= Math.ceil(value.size/1024) %>kB)' +
'<% } %>' +
'</div>' +
'<a href="#" class="btn _jsonform-delete"><i class="icon-remove" title="Remove"></i></a> ';

var inputFieldTemplate = function (type) {
return {
Expand Down Expand Up @@ -573,6 +580,15 @@ jsonform.elementTypes = {
}
});
},
'onInsert': function (evt, node) {
$(node.el).find('a._jsonform-delete').on('click', function (evt) {
$(node.el).find('._jsonform-preview').remove();
$(node.el).find('a._jsonform-delete').remove();
$(node.el).find('#' + escapeSelector(node.id)).val('');
evt.preventDefault();
return false;
});
},
'onSubmit': function (evt, elt) {
if (elt.ownerTree._transloadit_bound) {
return false;
Expand Down

0 comments on commit eb99744

Please sign in to comment.