Skip to content

Commit

Permalink
Merge pull request #167 from BitBagCommerce/OPSRC-645/Fix_validation_…
Browse files Browse the repository at this point in the history
…in_modals

Add checks for spaces in wishlist name
  • Loading branch information
dead-playmod authored Aug 17, 2022
2 parents dea38ad + dc8d5ee commit 94a68cc
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/Resources/assets/shop/js/wishlistModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,15 @@ export class WishlistModal {
_modalActions(template) {
const cancelBtn = template.querySelector('[data-bb-action="cancel"]');
const confirmBtn = template.querySelector('[data-bb-action="perform"]');
const input = template.querySelector('[data-bb-target="wishlists"] > [data-bb-target="input"]');

cancelBtn.addEventListener('click', () => {
this.actions.cancelAction();
this._closeModal();
});

confirmBtn.addEventListener('click', () => {
if(input && input.value === '') {
this._triggerInputError();
if (this._isInputValid(template)) {
this._triggerInputError(template);

return;
}
Expand All @@ -93,13 +92,20 @@ export class WishlistModal {
});
}

_triggerInputError() {
const body = document.querySelector('[data-bb-target="wishlists"]');
_isInputValid(template) {
const input = template.querySelector('[data-bb-target="wishlists"] > [data-bb-target="input"]');

return input && (input.value === null || input.value.match(/^ *$|^\t*$/) !== null);
}

_triggerInputError(template) {
const body = template.querySelector('[data-bb-target="wishlists"]');
const input = body.querySelector('[data-bb-target="input"]');
const div = body.querySelector('[data-bb-target="error"]');

input.classList.add('error');
div.classList.remove('hidden');
input.value = '';
}

_closeModal() {
Expand Down

0 comments on commit 94a68cc

Please sign in to comment.