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