Bugzilla – Attachment 108334 Details for
Bug 26218
Add JavaScript validation to date of birth field in OPAC registration form
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 26218: When a patron is created or edited from OPAC and the date of birth is invalid it showing invalid date of birth in the text box even if text box focus is out
0001-Bug-26218-When-a-patron-is-created-or-edited-from-OP.patch (text/plain), 6.65 KB, created by
Amit Gupta
on 2020-08-15 17:37:10 UTC
(
hide
)
Description:
Bug 26218: When a patron is created or edited from OPAC and the date of birth is invalid it showing invalid date of birth in the text box even if text box focus is out
Filename:
MIME Type:
Creator:
Amit Gupta
Created:
2020-08-15 17:37:10 UTC
Size:
6.65 KB
patch
obsolete
>From 01729f070fa2d553b16a0bf029fa7644e7884e8b Mon Sep 17 00:00:00 2001 >From: Amit Gupta <amit.gupta@informaticsglobal.com> >Date: Sat, 15 Aug 2020 15:27:25 +0000 >Subject: [PATCH] Bug 26218: When a patron is created or edited from OPAC and > the date of birth is invalid it showing invalid date of birth in the text box > even if text box focus is out. > >To Test: >1. Create the patron category from the staff page for ex: ST >2. Set PatronSelfRegistration to allow. >3. Allow category in PatronSelfRegistrationDefaultCategory for online registration from opac. >4. Go to /cgi-bin/koha/opac-memberentry.pl page. >5. Fill the form and give any invalid date and it show invalid date of birth in the date of birth text box even if text box focus is out. >6. Apply the patch. >7. Go to /cgi-bin/koha/opac-memberentry.pl page. >8. Fill the form and give any invalid date and it show blank value in the date of birth text box once text box focus is out. >--- > .../opac-tmpl/bootstrap/en/includes/calendar.inc | 76 +++++++++++++++++++++- > .../bootstrap/en/modules/opac-memberentry.tt | 2 +- > 2 files changed, 75 insertions(+), 3 deletions(-) > >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/calendar.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/calendar.inc >index 83d67c9..ba7556f 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/calendar.inc >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/calendar.inc >@@ -5,6 +5,53 @@ > var dformat = "[% dateformat | html %]"; > var sentmsg = 0; > if (debug > 1) {alert("dateformat: " + dformat + "\ndebug is on (level " + debug + ")");} >+ var MSG_PLEASE_ENTER_A_VALID_DATE = (_("Please enter a valid date (should match %s).")); >+ >+ function is_valid_date(date) { >+ // An empty string is considered as a valid date for convenient reasons. >+ if ( date === '' ) return 1; >+ var dateformat = dateformat_str = '[% Koha.Preference('dateformat') | html %]'; >+ if ( dateformat == 'us' ) { >+ if ( date.search(/^\d{2}\/\d{2}\/\d{4}($|\s)/) == -1 ) return 0; >+ dateformat = 'mm/dd/yy'; >+ } else if ( dateformat == 'metric' ) { >+ if ( date.search(/^\d{2}\/\d{2}\/\d{4}($|\s)/) == -1 ) return 0; >+ dateformat = 'dd/mm/yy'; >+ } else if (dateformat == 'iso' ) { >+ if ( date.search(/^\d{4}-\d{2}-\d{2}($|\s)/) == -1 ) return 0; >+ dateformat = 'yy-mm-dd'; >+ } else if ( dateformat == 'dmydot' ) { >+ if ( date.search(/^\d{2}\.\d{2}\.\d{4}($|\s)/) == -1 ) return 0; >+ } >+ try { >+ $.datepicker.parseDate(dateformat, date); >+ } catch (e) { >+ return 0; >+ }; >+ return 1; >+ } >+ >+ function get_dateformat_str(dateformat) { >+ var dateformat_str; >+ if ( dateformat == 'us' ) { >+ dateformat_str = 'mm/dd/yyyy'; >+ } else if ( dateformat == 'metric' ) { >+ dateformat_str = 'dd/mm/yyyy'; >+ } else if (dateformat == 'iso' ) { >+ dateformat_str = 'yyyy-mm-dd'; >+ } else if ( dateformat == 'dmydot' ) { >+ dateformat_str = 'dd.mm.yyyy'; >+ } >+ return dateformat_str; >+ } >+ >+ function validate_date (dateText, inst) { >+ if ( !is_valid_date(dateText) ) { >+ var dateformat_str = get_dateformat_str( '[% Koha.Preference('dateformat') | html %]' ); >+ alert(MSG_PLEASE_ENTER_A_VALID_DATE.format(dateformat_str)); >+ $('#'+inst.id).val(''); >+ } >+ } > > function Date_from_syspref(dstring) { > var dateX = dstring.split(/[-/.]/); >@@ -23,6 +70,20 @@ > } > } > >+ jQuery.validator.addMethod("is_date_after", >+ function(value, element, params) { >+ var from = Date_from_syspref( $(params).val() ); >+ var to = Date_from_syspref(value); >+ return to > from; >+ }); >+ >+ jQuery.validator.addMethod("date_on_or_after", >+ function(value, element, params) { >+ var from = Date_from_syspref( $(params).val() ); >+ var to = Date_from_syspref(value); >+ return to >= from; >+ }); >+ > /* Instead of including multiple localization files as you would normally see with > jQueryUI we expose the localization strings in the default configuration */ > jQuery(function($){ >@@ -64,7 +125,13 @@ > yearRange: "c-100:c" > }); > >- $( ".datepicker" ).datepicker(); >+ $( ".datepicker" ).datepicker({ >+ onClose: function(dateText, inst) { >+ validate_date(dateText, inst); >+ }, >+ }).on("change", function(e, value) { >+ if ( ! is_valid_date( $(this).val() ) ) {$(this).val("");} >+ }); > // http://jqueryui.com/demos/datepicker/#date-range > var dates = $( ".datepickerfrom, .datepickerto" ).datepicker({ > changeMonth: true, >@@ -77,7 +144,12 @@ > $.datepicker._defaults.dateFormat, > selectedDate, instance.settings ); > dates.not( this ).datepicker( "option", option, date ); >- } >+ }, >+ onClose: function(dateText, inst) { >+ validate_date(dateText, inst); >+ }, >+ }).on("change", function(e, value) { >+ if ( ! is_valid_date( $(this).val() ) ) {$(this).val("");} > }); > }); > //]]> >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt >index 7acd45a..db95fb4 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt >@@ -332,7 +332,7 @@ > <label for="borrower_dateofbirth">Date of birth:</label> > [% END %] > >- <input type="text" id="borrower_dateofbirth" name="borrower_dateofbirth" value="[% borrower.dateofbirth | $KohaDates %]" size="10" /> >+ <input type="text" id="borrower_dateofbirth" name="borrower_dateofbirth" value="[% borrower.dateofbirth | $KohaDates %]" size="10" class="datepicker" /> > > [% UNLESS action == 'edit' && !OPACPatronDetails %] > [% UNLESS ( mandatory.defined('dateofbirth') ) %] >-- >2.7.4 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 26218
:
108307
|
108308
| 108334 |
108335
|
108657