https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=14060
--- Comment #21 from Marc Véron <[email protected]> --- (In reply to Katrin Fischer from comment #20) > I'd really like to see this moving forward. So, if I understand correctly, > the current problem is that the validation is not triggered, when you enter > the date without using the datepicker? Hi Katrin, That seems to be one of the problems, but I think some problems hide other ones. I write down som notes I did while playing with the code, just pro memoria. One finding is that in borrower_debarments.inc, the id manual_restriction_form is not on the form, but on the fieldset: <fieldset class="rows" id="manual_restriction_form"> After moving the form tag, I was able to add a validation to the form, something like: mrform.on("submit",function(e) { var testDate = $("#rexpiration").val(); if (!validate_date( testDate )) { e.preventDefault(); return false; } return true; }); Then I tweaked is_valid_date(date) to return false if it gets dates like 1.1.2014 etc. (depending on the dateformat syspref), something like: function is_valid_date(date) { var dateformat = dateformat_str = '[% Koha.Preference('dateformat') %]'; if ( dateformat == 'us' ) { if (! date.match('[0-9]{2}/[0-9]{2}/[0-9]{4}') ) return 0; dateformat = 'mm/dd/yy'; dateformat_str = 'mm/dd/yyyy'; } else if ( dateformat == 'metric' ) { if (! date.match('[0-9]{2}/[0-9]{2}/[0-9]{4}') ) return 0; dateformat = 'dd/mm/yy'; dateformat_str = 'dd/mm/yyyy'; } else if (dateformat == 'iso' ) { if (! date.match('[0-9]{2}-[0-9]{2}-[0-9]{4}') ) return 0; dateformat = 'yy-mm-dd'; dateformat_str = 'yyyy-mm-dd'; } else if ( dateformat == 'dmydot' ) { if (! date.match('[0-9]{2}.[0-9]{2}.[0-9]{4}') ) return 0; dateformat = 'dd.mm.yy'; dateformat_str = 'dd.mm.yyyy'; } try { $.datepicker.parseDate(dateformat, date); } catch (e) { return 0; }; return 1; } Then I tweaked the function validate_date to return true / false (in calendar.inc) function validate_date (dateText, inst) { if ( !is_valid_date(dateText) ) { var dateformat_str = '[% Koha.Preference('dateformat') %]'; alert(MSG_PLEASE_ENTER_A_VALID_DATE.format(dateformat_str)); if (inst) { $('#'+inst.id).val(''); } return 0; } return 1; } (The if (inst) was to avoid a JavaScript error) Now I could trigger the validation. But one problem now was that empty dates could no longer be saved. I have no more time at the moment to dig deeper, but maybe the notes can help somebody else to find a solution. -- You are receiving this mail because: You are watching all bug changes. _______________________________________________ Koha-bugs mailing list [email protected] http://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-bugs website : http://www.koha-community.org/ git : http://git.koha-community.org/ bugs : http://bugs.koha-community.org/
