JSFiddle - React, Tailwind, and code Playground
by hollandben
JavaScript
$(function() {
var dates = $("#date_of_incident, #date_of_resolution").datetimepicker({
dateFormat: 'yy-mm-dd',
timeFormat: 'hh:mm',
showAnim: 'slideDown',
minDate: '-1d',
onSelect: function(selectedDate) {
var option = this.id === "date_of_incident" ? "minDate" : "maxDate",
instance = $(this).data("datepicker"),
date = $.datepicker.parseDate(
instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
dates.not(this).datepicker("option", option, date);
}
});
$(".date").change(calculateTimeDifference);
$('form#incident').submit(function() {
var errors = [];
$('#incident .error').removeClass('error');
var incident = $('#date_of_incident').val();
var explanation = $('#explanation').val();
if (incident === "") {
errors.push('date_of_incident');
}
if (explanation === "") {
errors.push('explanation');
}
if (errors.length !== 0) {
$.each(errors, function(i, value) {
$('#incident #' + value).addClass('error');
});
return false;
} else {
return true;
}
});
$('form#add_comment').submit(function() {
$('#add_comment .error').removeClass('error');
if ($('#add_comment #comment').val() === "") {
$('#add_comment #comment').addClass('error');
if ($('#add_comment #name').val() === "") {
$('#add_comment #name').addClass('error');
}
return false;
} else {
return true;
}
});
$('span.close-msg').click(function() {
$(this).parent('#msg').fadeOut();
});
});
function calculateTimeDifference() {
var incident = $('#date_of_incident').val();
var resolution = $('#date_of_resolution').val();
...