|
67 | 67 |
|
68 | 68 | {{ fields.numberField( |
69 | 69 | 'plugin_credit_quantity', |
70 | | - 0, |
| 70 | + 1, |
71 | 71 | __('Quantity consumed', 'credit'), |
72 | 72 | { |
73 | 73 | 'entity': entity_id, |
74 | 74 | 'condition': condition, |
75 | 75 | 'max': default_credit_max, |
76 | | - 'min': 0, |
| 76 | + 'min': 1, |
| 77 | + 'disabled': not consume or not default_credit, |
77 | 78 | 'helper': __('Maximum consumable quantity', 'credit') ~ ' : <b>' ~ default_credit_max, |
78 | | - 'field_class': 'col-6 col-sm-6', |
| 79 | + 'field_class': 'col-6 col-sm-6' ~ (not default_credit ? ' d-none' : ''), |
79 | 80 | 'input_class': 'col-xxl-5', |
80 | 81 | 'label_class': 'col-xxl-7', |
81 | 82 | 'rand': rand, |
|
88 | 89 | function showCreditDiv{{ rand }}() { |
89 | 90 | const creditVoucherBlock = document.getElementById('creditvoucherblock{{ rand }}'); |
90 | 91 | if (creditVoucherBlock) { |
91 | | - creditVoucherBlock.style.display = creditVoucherBlock.style.display === 'none' ? 'block' : 'none'; |
| 92 | + const isHidden = creditVoucherBlock.style.display !== 'none'; |
| 93 | + creditVoucherBlock.style.display = isHidden ? 'none' : 'block'; |
| 94 | + var consumeblock = document.querySelector('[name="credit_consume_{{ rand }}"]'); |
| 95 | + var quantity = consumeblock.querySelector('[id*="plugin_credit_quantity_{{ rand }}"]'); |
| 96 | + if (quantity) { |
| 97 | + quantity.disabled = isHidden; |
| 98 | + } |
92 | 99 | } |
93 | 100 | } |
94 | 101 |
|
95 | 102 | function getQuantityRemaining{{ rand }}(val) { |
96 | | - consumeblock = document.querySelector('[name="credit_consume_{{ rand }}"]'); |
97 | | - quantity = consumeblock.querySelector('[id*="plugin_credit_quantity_{{ rand }}"]'); |
98 | | - quantity_label = consumeblock.querySelector('[for*="plugin_credit_quantity_{{ rand }}"]'); |
| 103 | + var consumeblock = document.querySelector('[name="credit_consume_{{ rand }}"]'); |
| 104 | + var quantity = consumeblock.querySelector('[id*="plugin_credit_quantity_{{ rand }}"]'); |
| 105 | + var quantity_field = quantity.closest('.col-6'); |
| 106 | + var quantity_label = consumeblock.querySelector('[for*="plugin_credit_quantity_{{ rand }}"]'); |
99 | 107 | if (val == 0) { |
100 | | - quantity_label.style.display = 'none'; |
101 | | - quantity.style.display = 'none'; |
| 108 | + quantity_field.classList.add('d-none'); |
| 109 | + quantity.disabled = true; |
102 | 110 | quantity.max = 0; |
103 | 111 | quantity.value = 0; |
104 | 112 | quantity_label.querySelector('span.form-help').setAttribute('data-bs-title', __('Maximum consumable quantity', 'credit') + ' : 0 '); |
105 | 113 | quantity_label.querySelector('span.form-help').setAttribute('data-bs-content', __('Maximum consumable quantity', 'credit') + ' : 0 '); |
106 | 114 | } else { |
107 | | - quantity_label.style.display = 'block'; |
108 | | - quantity.style.display = 'block'; |
| 115 | + quantity_field.classList.remove('d-none'); |
| 116 | + quantity.disabled = false; |
109 | 117 |
|
110 | 118 | $.ajax({ |
111 | 119 | type: 'POST', |
|
115 | 123 | } |
116 | 124 | }).done(function (data) { |
117 | 125 | quantity.max = data; |
118 | | - quantity.value = 0; |
| 126 | + quantity.value = 1; |
119 | 127 | quantity_label.querySelector('span.form-help').setAttribute('data-bs-title', __('Maximum consumable quantity', 'credit') + ' : <b>' + data); |
120 | 128 | quantity_label.querySelector('span.form-help').setAttribute('data-bs-content', __('Maximum consumable quantity', 'credit') + ' : <b>' + data); |
121 | 129 | }); |
|
0 commit comments