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

Don’t add events in loop

parent 41529b92
...@@ -5,30 +5,28 @@ ...@@ -5,30 +5,28 @@
// datepicker, and make clicking on that element clear the field. // datepicker, and make clicking on that element clear the field.
// //
gl.MemberExpirationDate = function() { gl.MemberExpirationDate = function() {
$('.js-access-expiration-date').each(function(i, element) {
var expirationDateInput = $(element);
if (expirationDateInput.hasClass('hasDatepicker')) { return; }
function toggleClearInput() { 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', dateFormat: 'yy-mm-dd',
minDate: 1, minDate: 1,
onSelect: toggleClearInput onSelect: toggleClearInput
}); });
expirationDateInput.on('blur', toggleClearInput); inputs.next('.js-clear-input').on('click', function(event) {
toggleClearInput();
expirationDateInput.next('.js-clear-input').on('click', function(event) {
event.preventDefault(); 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); }).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