Bug 10267: Display the message only if the user enters too many characters

It seems better to display the warning if the user tries to enter too
many characters in the input.

Test plan:
With max=16
1. Copy/paste a string with 15, 16 and 17 characters
2. Enter a cardnumber of 15, 16, 17 characters
The warning should be displayed only the input overflows

Signed-off-by: Aleisha Amohia <aleishaamohia@hotmail.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Jonathan Druart 2017-10-24 18:10:40 -03:00
parent edaebf2565
commit 774b9d5fd8

View file

@ -35,16 +35,31 @@ $(document).ready(function() {
[% END %]
});
function update_cardnumber_warning(size){
var max_len = [% maxlength_cardnumber %];
if ( size >= max_len ) {
$("#cn_max").show();
} else {
$("#cn_max").hide();
}
}
$(document).ready(function() {
$("#cn_max").hide();
var max_len = [% maxlength_cardnumber %];
$("#cardnumber").change(function(){
if ( $("#cardnumber").val().length >= max_len ) {
$("#cn_max").show();
} else {
$("#cn_max").hide();
}
var content;
$("#cardnumber").on("keydown", function(e){
content = $(this).val();
});
$("#cardnumber").on("keyup", function(e){
// .val() will return the value of the input after the key has been released
var l = $(this).val().length;
if ( l == content.length + 1 ) { l--; }
update_cardnumber_warning(l);
});
$("#cardnumber").bind("paste", function(e){
var pastedData = e.originalEvent.clipboardData.getData('text');
update_cardnumber_warning(pastedData.length - 1);
} );
var toggle_quick_add = $(".toggle_quick_add");
$(toggle_quick_add).click(function(e){
toggle_quick_add.toggle();