Skip to content

Commit

Permalink
Added accept attribute on image widget, added alert message when lo…
Browse files Browse the repository at this point in the history
…aded an invalid image.
  • Loading branch information
Skirmantas Jurgaitis committed Apr 8, 2013
1 parent 739dd1c commit adbc350
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions oscar/forms/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ImageInput(FileInput):
dialog and allow for selecting a new or replacing image file.
"""
template_name = 'partials/image_input_widget.html'
attrs = {'accept': 'image/*'}

def render(self, name, value, attrs=None):
"""
Expand Down
1 change: 0 additions & 1 deletion oscar/static/oscar/js/oscar/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ var oscar = (function(o, $) {
return function(e) {
var imgDiv = $("#"+imgId);
imgDiv.children('img').attr('src', e.target.result);
imgDiv.children('button').remove();
};
})();
reader.readAsDataURL(evt.target.files[0]);
Expand Down
10 changes: 7 additions & 3 deletions oscar/templates/oscar/partials/image_input_widget.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
{% load i18n %}
<div id="{{ image_id }}" class="image-input">
<img src="{{ image_url }}" alt="thumbnail"/>
{% if not image_url %}
{% if image_url %}
<img src="{{ image_url }}" alt="thumbnail" />
{% else %}
<img alt="thumbnail"
onload="jQuery(this).next().hide()"
onerror="jQuery(this).next().show(); alert('{% trans 'Unrecognized image type!' %}')" />
<button class="btn btn-primary">{% trans "Upload Image" %}</button>
{% endif %}
<div class="input-field">
<input {{ input_attrs|safe }} />
<input {{ input_attrs|safe }} accept="image/*" />
</div>
</div>

0 comments on commit adbc350

Please sign in to comment.