lib.itmens/common/templates/widgets/image.html

22 lines
655 B
HTML
Raw Permalink Normal View History

<input type="{{ widget.type }}"
name="{{ widget.name }}"
{% include "django/forms/widgets/attrs.html" %}>
<img src="{{ widget.value|default_if_none:''|stringformat:'s' }}"
alt=""
id="previewImage"
style="margin:10px 0;
max-width:500px">
2020-07-03 15:36:23 +08:00
<script>
$("input[type='file'][name='{{ widget.name }}']").on("change", function () {
2020-07-03 15:36:23 +08:00
if (this.files && this.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#previewImage').attr('src', e.target.result);
}
reader.readAsDataURL(this.files[0]);
}
});
</script>