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);
function toggleClearInput() {
$(this).closest('.clearable-input').toggleClass('has-value', $(this).val() !== '');
}
if (expirationDateInput.hasClass('hasDatepicker')) { return; }
var inputs = $('.js-access-expiration-date');
function toggleClearInput() {
expirationDateInput.closest('.clearable-input').toggleClass('has-value', expirationDateInput.val() !== '');
}
inputs.datepicker({
dateFormat: 'yy-mm-dd',
minDate: 1,
onSelect: toggleClearInput
});
expirationDateInput.datepicker({
dateFormat: 'yy-mm-dd',
minDate: 1,
onSelect: toggleClearInput
});
inputs.next('.js-clear-input').on('click', function(event) {
event.preventDefault();
expirationDateInput.on('blur', toggleClearInput);
var input = $(this).closest('.clearable-input').find('.js-access-expiration-date');
input.datepicker('setDate', null);
toggleClearInput.call(input);
});
toggleClearInput();
inputs.on('blur', toggleClearInput);
expirationDateInput.next('.js-clear-input').on('click', function(event) {
event.preventDefault();
expirationDateInput.datepicker('setDate', null);
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