ui-messages-mixin.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * MageSpecialist
  3. *
  4. * NOTICE OF LICENSE
  5. *
  6. * This source file is subject to the Open Software License (OSL 3.0)
  7. * that is bundled with this package in the file LICENSE.txt.
  8. * It is also available through the world-wide-web at this URL:
  9. * http://opensource.org/licenses/osl-3.0.php
  10. * If you did not receive a copy of the license and are unable to
  11. * obtain it through the world-wide-web, please send an email
  12. * to info@magespecialist.it so we can send you a copy immediately.
  13. *
  14. * @copyright Copyright (c) 2017 Skeeller srl (http://www.magespecialist.it)
  15. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  16. */
  17. 'use strict';
  18. define(['MSP_ReCaptcha/js/registry'], function (registry) {
  19. return function (originalComponent) {
  20. return originalComponent.extend({
  21. /**
  22. * Initialize reset on messages
  23. * @returns {initialize}
  24. */
  25. initialize: function () {
  26. this._super();
  27. this.messageContainer.errorMessages.subscribe(function () {
  28. var
  29. i,
  30. captchaList = registry.captchaList(),
  31. tokenFieldsList = registry.tokenFields();
  32. for (i = 0; i < captchaList.length; i++) {
  33. // eslint-disable-next-line no-undef
  34. grecaptcha.reset(captchaList[i]);
  35. if (tokenFieldsList[i]) {
  36. tokenFieldsList[i].value = '';
  37. }
  38. }
  39. }, null, 'arrayChange');
  40. return this;
  41. }
  42. });
  43. };
  44. });