Commit 4d07319b authored by Douwe Maan's avatar Douwe Maan

Don’t add events in loop

parent 41529b92
......@@ -5,30 +5,28 @@
// datepicker, and make clicking on that element clear the field.
//
gl.MemberExpirationDate = function() {
$('.js-access-expiration-date').each(function(i, element) {
var expirationDateInput = $(element);
if (expirationDateInput.hasClass('hasDatepicker')) { return; }
function toggleClearInput() {
expirationDateInput.closest('.clearable-input').toggleClass('has-value', expirationDateInput.val() !== '');
$(this).closest('.clearable-input').toggleClass('has-value', $(this).val() !== '');
}
expirationDateInput.datepicker({
var inputs = $('.js-access-expiration-date');
inputs.datepicker({
dateFormat: 'yy-mm-dd',
minDate: 1,
onSelect: toggleClearInput
});
expirationDateInput.on('blur', toggleClearInput);
toggleClearInput();
expirationDateInput.next('.js-clear-input').on('click', function(event) {
inputs.next('.js-clear-input').on('click', function(event) {
event.preventDefault();
expirationDateInput.datepicker('setDate', null);
toggleClearInput();
});
var input = $(this).closest('.clearable-input').find('.js-access-expiration-date');
input.datepicker('setDate', null);
toggleClearInput.call(input);
});
inputs.on('blur', toggleClearInput);
inputs.each(toggleClearInput);
};
}).call(this);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment