All files daterange.js

100% Statements 10/10
100% Branches 8/8
100% Functions 3/3
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28      4x   2x     2x   2x 1x       4x   2x     2x   2x 1x        
// Ensures data from date cannot be set after to date and vice versa
 
export function setDateRange(fromDateInput, toDateInput) {
  fromDateInput.addEventListener('change', () => {
    // when fromDate changes the value set is assigned to fromDateValue
    const fromDateValue = fromDateInput.value;
 
    // sets the minimum toDateInput to the date set by fromDateValue
    toDateInput.min = fromDateValue;
 
    if (toDateInput.value && toDateInput.value < fromDateValue) {
      toDateInput.value = '';
    }
  });
 
  toDateInput.addEventListener('change', () => {
    // when toDate changes the value set is assigned to toDateValue
    const toDateValue = toDateInput.value;
 
    // sets the maximum fromDateInput to the date set by toDateValue
    fromDateInput.max = toDateValue;
 
    if (fromDateInput.value && fromDateInput.value > toDateValue) {
      fromDateInput.value = '';
    }
  });
}