From 214952e7b6ff3edf9a7e66786f475d61dd65fa0f Mon Sep 17 00:00:00 2001 From: Nicolas F Date: Wed, 4 Oct 2017 02:03:22 +0200 Subject: [PATCH] Disable report button on empty reason (#374) Previously, people couldn't quite tell you needed to give a report reason. Now we disable the submit button until there is a reason, and flask.flash() if someone manages to submit an empty reason anyway. --- nyaa/templates/view.html | 10 +++++++++- nyaa/views/torrents.py | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/nyaa/templates/view.html b/nyaa/templates/view.html index cb80e63..ae792d4 100644 --- a/nyaa/templates/view.html +++ b/nyaa/templates/view.html @@ -200,7 +200,7 @@ {{ render_field(report_form.reason, class_='form-control', maxlength=255) }}
- +
@@ -214,6 +214,14 @@ // Focus the report text field once the modal is opened. $('#reportModal').on('shown.bs.modal', function () { $('#reason').focus(); + $('#reportSubmit').attr('disabled', true); + }); + $('#reason').on('input', function(e) { + if($('#reason').val().length > 0) { + $('#reportSubmit').removeAttr('disabled'); + } else { + $('#reportSubmit').attr('disabled', true); + } }); {% endif %} diff --git a/nyaa/views/torrents.py b/nyaa/views/torrents.py index 3f1a34b..fd14bcb 100644 --- a/nyaa/views/torrents.py +++ b/nyaa/views/torrents.py @@ -376,6 +376,8 @@ def submit_report(torrent_id): db.session.add(report) db.session.commit() flask.flash('Successfully reported torrent!', 'success') + elif len(form.reason.data) == 0: + flask.flash('Please give a report reason!', 'danger') return flask.redirect(flask.url_for('torrents.view', torrent_id=torrent_id))