discount-codes.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /**
  2. * Copyright © Magento, Inc. All rights reserved.
  3. * See COPYING.txt for license details.
  4. */
  5. define([
  6. 'jquery',
  7. 'jquery/ui'
  8. ], function ($) {
  9. 'use strict';
  10. $.widget('mage.discountCode', {
  11. options: {
  12. },
  13. /** @inheritdoc */
  14. _create: function () {
  15. this.couponCode = $(this.options.couponCodeSelector);
  16. this.removeCoupon = $(this.options.removeCouponSelector);
  17. $(this.options.applyButton).on('click', $.proxy(function () {
  18. this.couponCode.attr('data-validate', '{required:true}');
  19. this.removeCoupon.attr('value', '0');
  20. $(this.element).validation().submit();
  21. }, this));
  22. $(this.options.cancelButton).on('click', $.proxy(function () {
  23. this.couponCode.removeAttr('data-validate');
  24. this.removeCoupon.attr('value', '1');
  25. this.element.submit();
  26. }, this));
  27. }
  28. });
  29. return $.mage.discountCode;
  30. });