fix duplicate scrape | close #57

This commit is contained in:
doubaniux 2020-10-26 00:55:36 +01:00
parent 9bb2a72049
commit ae2393e9a4
3 changed files with 22 additions and 7 deletions

View file

@ -71,7 +71,7 @@ ISBN: 9787020104345
{{ form.media }}
{{ form }}
</form>
<a href="{% url 'books:scrape' %}" class="button add-button submit">{% trans '剽取!' %}</a>
<a href="#" class="button add-button submit">{% trans '剽取!' %}</a>
</div>
</div>
</div>
@ -99,9 +99,13 @@ ISBN: 9787020104345
</div>
<script>
// mark required
$("#content input[required]").each(function () {
$(this).prev().prepend("*");
})
$("#content input[required]").each(function () {
$(this).prev().prepend("*");
});
$('form').submit(function () {
$(this).find("input[type='submit']").prop('disabled', true);
$(this).find("button[type='submit']").prop('disabled', true);
});
</script>
</body>

View file

@ -2,7 +2,14 @@ $(document).ready( function() {
$(".submit").click(function(e) {
e.preventDefault();
$("#scrapeForm form").submit();
let form = $("#scrapeForm form");
if (form.data('submitted') === true) {
// Previously submitted - don't submit again
} else {
// Mark it so that the next submit can be ignored
form.data('submitted', true);
$("#scrapeForm form").submit();
}
});
// assume there is only one input[file] on page

View file

@ -69,7 +69,7 @@
{% endfor %}
</form>
<a href="{% url 'movies:scrape' %}" class="button add-button submit">{% trans '剽取!' %}</a>
<a href="#" class="button add-button submit">{% trans '剽取!' %}</a>
</div>
</div>
</div>
@ -99,7 +99,11 @@
// mark required
$("#content input[required]").each(function () {
$(this).prev().prepend("*");
})
});
$('form').submit(function () {
$(this).find("input[type='submit']").prop('disabled', true);
$(this).find("button[type='submit']").prop('disabled', true);
});
</script>
</body>