BigW Consortium Gitlab

member_expiration_date.js 1.24 KB
Newer Older
1
/* eslint-disable func-names, space-before-function-paren, vars-on-top, no-var, object-shorthand, comma-dangle, max-len */
2 3 4 5 6 7
(function() {
  // Add datepickers to all `js-access-expiration-date` elements. If those elements are
  // children of an element with the `clearable-input` class, and have a sibling
  // `js-clear-input` element, then show that element when there is a value in the
  // datepicker, and make clicking on that element clear the field.
  //
8
  gl.MemberExpirationDate = function() {
9 10 11
    function toggleClearInput() {
      $(this).closest('.clearable-input').toggleClass('has-value', $(this).val() !== '');
    }
12

13
    var inputs = $('.js-access-expiration-date');
14

15 16 17
    inputs.datepicker({
      dateFormat: 'yy-mm-dd',
      minDate: 1,
18 19 20 21
      onSelect: function () {
        $(this).trigger('change');
        toggleClearInput.call(this);
      }
22
    });
23

24 25
    inputs.next('.js-clear-input').on('click', function(event) {
      event.preventDefault();
26

27
      var input = $(this).closest('.clearable-input').find('.js-access-expiration-date');
28 29
      input.datepicker('setDate', null)
        .trigger('change');
30 31
      toggleClearInput.call(input);
    });
32

33
    inputs.on('blur', toggleClearInput);
34

35
    inputs.each(toggleClearInput);
36 37
  };
}).call(this);