|
432 | 432 |
|
433 | 433 | // generate voucher code |
434 | 434 | $o.timepass.editor |
435 | | - .on('mousedown', $o.generateVoucherCode, function() { |
436 | | - generateVoucherCode($(this).parents($o.timepass.wrapper)); |
| 435 | + .on('mousedown', $o.generateVoucherCode, function(e) { |
| 436 | + if ( $(this).is('[disabled=disabled]') ) { |
| 437 | + e.preventDefault(); |
| 438 | + return false; |
| 439 | + } |
| 440 | + generateVoucherCode($(this).parents($o.timepass.wrapper)); |
437 | 441 | }) |
438 | 442 | .on('click', $o.generateVoucherCode, function(e) { |
439 | 443 | e.preventDefault(); |
|
551 | 555 |
|
552 | 556 | // Generate voucher code. |
553 | 557 | $o.subscription.editor |
554 | | - .on('mousedown', $o.generateVoucherCode, function() { |
555 | | - generateVoucherCode($(this).parents($o.subscription.wrapper)); |
| 558 | + .on('mousedown', $o.generateVoucherCode, function(e) { |
| 559 | + if ( $(this).is('[disabled=disabled]') ) { |
| 560 | + e.preventDefault(); |
| 561 | + return false; |
| 562 | + } |
| 563 | + generateVoucherCode($(this).parents($o.subscription.wrapper)); |
556 | 564 | }) |
557 | 565 | .on('click', $o.generateVoucherCode, function(e) { |
558 | 566 | e.preventDefault(); |
|
692 | 700 | validateVoucherCode = function( voucherInput, $wrapper, type ) { |
693 | 701 | var voucherCode = voucherInput.val(); |
694 | 702 |
|
695 | | - if (voucherCode.length === 6) { |
696 | | - |
| 703 | + if (voucherCode.length === 6 ) { |
697 | 704 | var globalVouchers = $o.globalVouchers.data.vouchers; |
698 | 705 | if ( typeof $o.globalVouchers.data.vouchers === 'string' ) { |
699 | 706 | globalVouchers = JSON.parse($o.globalVouchers.data.vouchers); |
|
751 | 758 | return; |
752 | 759 | } |
753 | 760 | $($o.subscription.actions.save).removeAttr('disabled'); |
754 | | - $($o.subscription.actions.save).attr('href', '#'); |
| 761 | + $wrapper.find($o.generateVoucherCode).removeAttr('disabled'); |
| 762 | + $($o.subscription.actions.save).attr('href', 'javascript:void(0);'); |
755 | 763 | } else if ( isGlobal ) { |
756 | 764 | if (true === voucherExists) { |
757 | 765 | $wrapper.find('.lp_js_voucher_msg').text(lpVars.i18n.voucherExists); |
|
761 | 769 | return; |
762 | 770 | } |
763 | 771 | $o.saveGlobalDefaultPrice.removeAttr('disabled'); |
764 | | - $o.saveGlobalDefaultPrice.attr('href', '#'); |
| 772 | + $wrapper.find($o.generateVoucherCode).removeAttr('disabled'); |
| 773 | + $o.saveGlobalDefaultPrice.attr('href', 'javascript:void(0);'); |
765 | 774 | } else { |
766 | 775 | if (true === voucherExists) { |
767 | 776 | $wrapper.find('.lp_js_voucher_msg').text(lpVars.i18n.voucherExists); |
|
771 | 780 | return; |
772 | 781 | } |
773 | 782 | $($o.timepass.actions.save).removeAttr('disabled'); |
774 | | - $($o.timepass.actions.save).attr('href', '#'); |
| 783 | + $wrapper.find($o.generateVoucherCode).removeAttr('disabled'); |
| 784 | + $($o.timepass.actions.save).attr('href', 'javascript:void(0);'); |
775 | 785 | } |
776 | 786 |
|
777 | 787 | voucherInput.parent().attr('data-code', voucherCode); |
778 | 788 | voucherInput.parent().find('input[name="voucher_code[]"]').val(voucherCode); |
779 | 789 | } else { |
780 | 790 | $wrapper.find('.lp_js_voucher_msg').text(lpVars.i18n.codeTooShort); |
781 | 791 | $wrapper.find('.lp_js_voucher_msg').css('display', 'block'); |
| 792 | + // Disabled save button if there are less than 6 characters. #1397 |
| 793 | + $wrapper.find('.button-primary').attr('disabled', 'disabled'); |
| 794 | + $wrapper.find($o.generateVoucherCode).attr('disabled', 'disabled'); |
782 | 795 | return; |
783 | 796 | } |
784 | 797 |
|
|
0 commit comments