Skip to content

Commit

Permalink
Merge pull request #1409 from ix5/delete-fixes
Browse files Browse the repository at this point in the history
Prevent <escape> key from confirming deletions
  • Loading branch information
mrjoes committed Jan 9, 2017
2 parents f29d389 + acbc75a commit 5469b34
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions flask_admin/templates/bootstrap3/admin/model/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -202,5 +202,22 @@
);
{% endif %}
})(jQuery);

// Catch exception when closing dialog with <esc> key
// and prevent accidental deletions.
function safeConfirm(msg) {
try {
var isconfirmed = confirm(msg);
if (isconfirmed == true) {
return true;
}
else {
return false;
}
}
catch(err) {
return false;
}
}
</script>
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
{% elif csrf_token %}
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
{% endif %}
<button onclick="return confirm('{{ _gettext('Are you sure you want to delete this record?') }}');" title="Delete record">
<button onclick="return safeConfirm('{{ _gettext('Are you sure you want to delete this record?') }}');" title="Delete record">
<span class="fa fa-trash glyphicon glyphicon-trash"></span>
</button>
</form>
Expand Down

0 comments on commit 5469b34

Please sign in to comment.