Skip to content
This repository has been archived by the owner on Mar 28, 2021. It is now read-only.

Commit

Permalink
make character countdown work on all edit forms
Browse files Browse the repository at this point in the history
  • Loading branch information
thraxil committed Mar 11, 2016
1 parent 105b639 commit d6ab31a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
37 changes: 23 additions & 14 deletions spokehub/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -195,24 +195,33 @@ <h1>The site is not active yet. Please stand by.</h1>
</script>

<script>
$(document).ready(function() {
var text_max = 140;
$('#textarea_feedback').html(text_max + ' characters remaining');
var updateFeedback = function(textarea) {
if (textarea.val() === undefined) {
return;
}
var text_max = 140;
var text_length = textarea.val().length;
var text_remaining = text_max - text_length;

$('#textarea_feedback').html(text_remaining + ' characters remaining');

$('#textarea').keyup(function() {
var text_length = $('#textarea').val().length;
var text_remaining = text_max - text_length;
if (text_remaining < 10) {
$('#textarea_feedback').css("color", "#ec008c");
}
else {
$('#textarea_feedback').css("color", "#000");
}
};

$('#textarea_feedback').html(text_remaining + ' characters remaining');

if (text_remaining < 10) {
$('#textarea_feedback').css("color", "#ec008c");
}
else {
$('#textarea_feedback').css("color", "#000");
}
$(document).ready(function() {
// register handlers
$('#textarea').keyup(function() { updateFeedback($('#textarea')); });
$('#id_body').keyup(function() { updateFeedback($('#id_body')); });

});
// initialize feedback (for edit views)
updateFeedback($('#textarea'));
updateFeedback($('#id_body'));
});
</script>

Expand Down
1 change: 1 addition & 0 deletions spokehub/templates/main/conversation_update_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<form action="." method="post">{% csrf_token %}
<fieldset>
{{form|bootstrap}}
<p id="textarea_feedback"></p>
<a class="btn btn-danger pull-right" href="{{object.get_delete_url}}">Delete Conversation</a>
<input type="submit" value="Save" class="btn btn-primary"/>
</fieldset>
Expand Down
1 change: 1 addition & 0 deletions spokehub/templates/main/reply_update_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<form action="." method="post" enctype="multipart/form-data">{% csrf_token %}
<fieldset>
{{form|bootstrap}}
<p id="textarea_feedback"></p>
<a class="btn btn-danger pull-right" href="{% url 'delete-reply' object.id }">Delete Response</a>
<input type="submit" value="Save" class="btn btn-primary"/>
</fieldset>
Expand Down

0 comments on commit d6ab31a

Please sign in to comment.