Commit bd84e7a0 authored by felix.herrmann's avatar felix.herrmann
Browse files

feat(maxlength): Attach to any element with .textarea or .textinput class and...

feat(maxlength): Attach to any element with .textarea or .textinput class and a maxlength attribute a div which shows the number of remaining chars left to type if remaining number falls under 50 chars
parent c03ececa
......@@ -151,3 +151,33 @@ $(document).on('beforeSend.ic', function (event, el, data) {
}
});
/*
* Attach to any element with .textarea or .textinput class and a maxlength
* attribute a div which shows the number of remaining chars left to type
* if remaining number falls under 50 chars
*/
$(document).on('keyup','.textarea, .textinput', function() {
// get maxlength attribute
var maxLength = $(this).attr( "maxlength" );
if (maxLength != null){
var length = $(this).val().length;
var remainingLength = maxLength-length;
// get this elements id
var elemId = $(this).attr('id');
if (remainingLength < 50) {
// construct new id using this elements id
var charsLeftId = elemId + '_chars_left';
if ($('#' + charsLeftId).length) {
// if new div exists set text
$('#'+charsLeftId).html(remainingLength);
}
else {
// create new div using new id
$("<div class='chars-left' id='" + charsLeftId + "'>" + remainingLength + "</div>").insertAfter('#' + elemId);
}
}
}
});
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment