Last active
December 6, 2019 12:32
-
-
Save LowerDeez/13ef77d606b0fc5d98a92544d756fbc1 to your computer and use it in GitHub Desktop.
Django. JS in admin panel for checking letters count.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SomeModelAdmin(admin.ModelAdmin): | |
class Media: | |
js = ['path/to/script.js'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by Developer on 15.09.2017. | |
*/ | |
(function ($) { | |
$(document).ready(function ($) { | |
function chars_check_count(text_field) { | |
text_field.keyup(function (event) { | |
var max_length = $(this).attr('maxlength'); | |
var charsCurrent = $(this).val().length; | |
var spanChars = $(this).next('.help'); | |
if (charsCurrent >= max_length){ | |
spanChars.css('color', 'red').text(charsCurrent + '/' + max_length) | |
.append("<span> characters</span>"); | |
} | |
else | |
{ | |
spanChars.css('color', 'green').text(charsCurrent + '/' + max_length) | |
.append("<span> characters</span>"); | |
} | |
}) | |
} | |
$('input[type=text]').each(function(){ | |
chars_check_count($(this)) | |
}); | |
}); | |
})(django.jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment