debian-mirror-gitlab/app/assets/javascripts/member_expiration_date.js

37 lines
1.1 KiB
JavaScript
Raw Normal View History

2016-09-13 17:45:13 +05:30
(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() {
function toggleClearInput() {
$(this).closest('.clearable-input').toggleClass('has-value', $(this).val() !== '');
}
var inputs = $('.js-access-expiration-date');
inputs.datepicker({
dateFormat: 'yy-mm-dd',
minDate: 1,
2016-11-03 12:29:30 +05:30
onSelect: function () {
$(this).trigger('change');
toggleClearInput.call(this);
}
2016-09-13 17:45:13 +05:30
});
inputs.next('.js-clear-input').on('click', function(event) {
event.preventDefault();
var input = $(this).closest('.clearable-input').find('.js-access-expiration-date');
2016-11-03 12:29:30 +05:30
input.datepicker('setDate', null)
.trigger('change');
2016-09-13 17:45:13 +05:30
toggleClearInput.call(input);
});
inputs.on('blur', toggleClearInput);
inputs.each(toggleClearInput);
};
}).call(this);