From 774b9d5fd8197ffb40096be89947b3d3efe61398 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 24 Oct 2017 18:10:40 -0300 Subject: [PATCH] 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 Signed-off-by: Kyle M Hall Signed-off-by: Jonathan Druart --- .../prog/en/modules/members/memberentrygen.tt | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt index 1c1d6e8d2e..8a17653c03 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt @@ -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(); -- 2.39.5