gitlab-org--gitlab-foss/app/assets/javascripts/member_expiration_date.js

33 lines
1 KiB
JavaScript
Raw Normal View History

(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.
//
gl.MemberExpirationDate = function() {
2016-08-18 20:41:18 -04:00
function toggleClearInput() {
$(this).closest('.clearable-input').toggleClass('has-value', $(this).val() !== '');
}
2016-08-18 20:41:18 -04:00
var inputs = $('.js-access-expiration-date');
2016-08-18 20:41:18 -04:00
inputs.datepicker({
dateFormat: 'yy-mm-dd',
minDate: 1,
onSelect: toggleClearInput
});
2016-08-18 20:41:18 -04:00
inputs.next('.js-clear-input').on('click', function(event) {
event.preventDefault();
2016-08-18 20:41:18 -04:00
var input = $(this).closest('.clearable-input').find('.js-access-expiration-date');
input.datepicker('setDate', null);
toggleClearInput.call(input);
});
2016-08-18 20:41:18 -04:00
inputs.on('blur', toggleClearInput);
2016-08-18 20:41:18 -04:00
inputs.each(toggleClearInput);
};
}).call(this);