Bug 10267: Show error message if user tries to enter too many characters for cardnumber

This patch displays a message if the user tries to enter more than the
max number of characters for a cardnumber.

To test:
1) Apply patch and go to Patrons -> New patron
2) Scroll down to Card number
3) Put in any characters. Notice that when you have entered the max
number of characters, you are unable to type any more.
4) Click out of the text field (so it loses focus), the error message will show up.
5) if you backspace some characters and click out of the text field
again, the message should disappear

Sponsored-by: Catalyst IT

Followed test plan, works as expected
Signed-off-by: Marc Véron <veron@veron.ch>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

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:
Aleisha Amohia 2017-04-20 03:35:47 +00:00 committed by Jonathan Druart
parent 63a9c26fe5
commit edaebf2565

View file

@ -36,7 +36,15 @@ $(document).ready(function() {
});
$(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 toggle_quick_add = $(".toggle_quick_add");
$(toggle_quick_add).click(function(e){
toggle_quick_add.toggle();
@ -635,15 +643,15 @@ $(document).ready(function() {
[% END %]
[% IF minlength_cardnumber == maxlength_cardnumber %]
<input type="text" id="cardnumber" name="cardnumber" size="20" value="[% cardnumber | html %]" minlength="[% minlength_cardnumber %]" maxlength="[% maxlength_cardnumber %]" />
[% IF mandatorycardnumber and not autoMemberNum %]<span class="required">Required</span>[% END %]
[% IF mandatorycardnumber and not autoMemberNum %]<span class="required">Required</span>[% END %]<span id="cn_max" class="required">Card number must not be more than [% maxlength_cardnumber %] characters.</span>
<div class="hint">Card number must be exactly [% minlength_cardnumber %] characters.</div>
[% ELSIF minlength_cardnumber && maxlength_cardnumber %]
<input type="text" id="cardnumber" name="cardnumber" size="20" value="[% cardnumber | html %]" minlength="[% minlength_cardnumber %]" maxlength="[% maxlength_cardnumber %]" />
[% IF mandatorycardnumber and not autoMemberNum %]<span class="required">Required</span>[% END %]
[% IF mandatorycardnumber and not autoMemberNum %]<span class="required">Required</span>[% END %]<span id="cn_max" class="required">Card number must not be more than [% maxlength_cardnumber %] characters.</span>
<div class="hint">Card number must be between [% minlength_cardnumber %] and [% maxlength_cardnumber %] characters.</div>
[% ELSIF maxlength_cardnumber %]
<input type="text" id="cardnumber" name="cardnumber" size="20" value="[% cardnumber | html %]" maxlength="[% maxlength_cardnumber %]" />
[% IF mandatorycardnumber and not autoMemberNum %]<span class="required">Required</span>[% END %]
[% IF mandatorycardnumber and not autoMemberNum %]<span class="required">Required</span>[% END %]<span id="cn_max" class="required">Card number must not be more than [% maxlength_cardnumber %] characters.</span>
<div class="hint">Card number can be up to [% maxlength_cardnumber %] characters.</div>
[% ELSE %]
<input type="text" id="cardnumber" name="cardnumber" size="20" value="[% cardnumber | html %]" />