Skip to content

Commit

Permalink
Merge pull request #248 from biocore/csymons_i18n_date_validation
Browse files Browse the repository at this point in the history
Adjust date validation for i18n issues
  • Loading branch information
cassidysymons authored Oct 14, 2022
2 parents c3fe70b + 2cfed5b commit 7fc0212
Showing 1 changed file with 31 additions and 17 deletions.
48 changes: 31 additions & 17 deletions microsetta_interface/templates/sample.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,6 @@
<script>
$(document).ready(function(){
$("form").submit(function(e) {
var date = $("#sample_date").val()
date = new Date(date);
var lower_limit = new Date();
lower_limit .setFullYear( lower_limit.getFullYear() - 10 );
var upper_limit = new Date();
upper_limit .setMonth(upper_limit.getMonth() + 1);
if(date < lower_limit) {
alert("{{ _('Please select a date within the last 10 years.') }}")
e.preventDefault(e);
} else if (date > upper_limit) {
alert("{{ _('Please select a date within the next 30 days.') }}")
e.preventDefault(e);
}
});
let form_name = 'sample_form';
preventImplicitSubmission(form_name);
Expand Down Expand Up @@ -85,6 +69,34 @@
//expected localized date format matching the datepicker settings.
}, "{{ _('Required Format: MM/DD/YYYY') }}");
$.validator.addMethod("dateInPast", function(value, element)
{
let check;
let date = new Date($("#sample_date_normalized").val());
var lower_limit = new Date();
lower_limit.setFullYear(lower_limit.getFullYear() - 10);
if(date < lower_limit) {
check = false;
} else {
check = true;
}
return this.optional(element) || check;
}, "{{ _('Please select a date within the last 10 years.') }}");
$.validator.addMethod("dateInFuture", function(value, element)
{
let check;
let date = new Date($("#sample_date_normalized").val());
var upper_limit = new Date();
upper_limit.setMonth(upper_limit.getMonth() + 1);
if(date > upper_limit) {
check = false;
} else {
check = true;
}
return this.optional(element) || check;
}, "{{ _('Please select a date within the next 30 days.') }}");
$("#sample_date").datepicker(datepicker_args)
$( "#sample_time" ).timepicker({
Expand Down Expand Up @@ -120,7 +132,9 @@
// on the right side
sample_date: {
required: true,
monthDayYear: true
monthDayYear: true,
dateInPast: true,
dateInFuture: true
},
sample_time: "required",
{% if not is_environmental %}
Expand Down

0 comments on commit 7fc0212

Please sign in to comment.