Add min/max validation for date, datetime, and number questions (#1858)

This commit is contained in:
Raphael Michel
2020-11-27 11:02:07 +01:00
committed by GitHub
parent 921b28f8d4
commit 66af5973ec
13 changed files with 262 additions and 13 deletions

View File

@@ -113,6 +113,14 @@ var form_handlers = function (el) {
close: 'fa fa-remove'
},
};
if ($(this).is('[data-min]')) {
opts["minDate"] = $(this).attr("data-min");
opts["viewDate"] = $(this).attr("data-min");
}
if ($(this).is('[data-max]')) {
opts["maxDate"] = $(this).attr("data-max");
opts["viewDate"] = $(this).attr("data-max");
}
if ($(this).is('[data-is-payment-date]'))
opts["daysOfWeekDisabled"] = JSON.parse($("body").attr("data-payment-weekdays-disabled"));
$(this).datetimepicker(opts);

View File

@@ -102,6 +102,10 @@ $(function () {
var show = $("#id_type").val() == "C" || $("#id_type").val() == "M";
$("#answer-options").toggle(show);
$("#valid-date").toggle($("#id_type").val() == "D");
$("#valid-datetime").toggle($("#id_type").val() == "W");
$("#valid-number").toggle($("#id_type").val() == "N");
show = $("#id_type").val() == "B" && $("#id_required").prop("checked");
$(".alert-required-boolean").toggle(show);
}