|
4 | 4 | :class="checkbox.class" |
5 | 5 | v-for="checkbox in checkboxes" |
6 | 6 | :key="checkbox.id" |
| 7 | + @click="checkShift($event)" |
7 | 8 | > |
8 | | - <input :type="checkbox.type" /> |
| 9 | + <input :type="checkbox.type" :id="checkbox.id" /> |
9 | 10 | <p>{{ checkbox.paragraphContent }}</p> |
10 | 11 | </div> |
11 | 12 | </div> |
@@ -72,41 +73,44 @@ export default { |
72 | 73 | id: 9, |
73 | 74 | }, |
74 | 75 | ], |
| 76 | + inBetween: false, |
| 77 | + shiftKey: false, |
| 78 | + lastChecked: false, |
75 | 79 | }; |
76 | 80 | }, |
77 | | -}; |
78 | | -const checkboxes = document.querySelectorAll("input[type=checkbox]"); |
79 | | -
|
80 | | -let lastChecked; |
| 81 | + methods: { |
| 82 | + checkShift(event) { |
| 83 | + // variable to store the shift key boolean value |
| 84 | + this.shiftKey = event.shiftKey; |
81 | 85 |
|
82 | | -function checkShift(e) { |
83 | | - // variable to store the shift key boolean value |
84 | | - let shiftKey = e.shiftKey; |
85 | | - // Flag to help us determine if a checkbox is inBetween two checkboxes |
86 | | - let inBetween = false; |
87 | | -
|
88 | | - // Checking if the shiftKey is pressed and that the current checkbox is checked |
89 | | - if (shiftKey && this.checked) { |
90 | | - // Iterating over the checkboxes |
91 | | - checkboxes.forEach((checkbox) => { |
92 | | - // Check if the current checkbox is one the 'begin' or the 'end' |
93 | | - if (checkbox === this || checkbox === lastChecked) { |
94 | | - // Reverse the value of inBetween since it's not inBetween the start and end |
95 | | - inBetween = !inBetween; |
96 | | - } |
97 | | - // if the current checkbox is inBetween, check it. |
98 | | - if (inBetween) { |
99 | | - checkbox.checked = true; |
| 86 | + // Checking if the shiftKey is pressed and that the current checkbox is checked |
| 87 | + if (this.shiftKey && this.checked) { |
| 88 | + // Iterating over the checkboxes |
| 89 | + // Need to translate that later |
| 90 | + // checkboxes.forEach((checkbox) => { |
| 91 | + // // Check if the current checkbox is one the 'begin' or the 'end' |
| 92 | + // if (checkbox === this || checkbox === this.lastChecked) { |
| 93 | + // // Reverse the value of inBetween since it's not inBetween the start and end |
| 94 | + // this.inBetween = !this.inBetween; |
| 95 | + // } |
| 96 | + // // if the current checkbox is inBetween, check it. |
| 97 | + // if (this.inBetween) { |
| 98 | + // checkbox.checked = true; |
| 99 | + // } |
| 100 | + // }); |
| 101 | + //TODO = Find a way to reverse this in a way that when the shift key is pressed on a checked box, it will make them all unchecked |
100 | 102 | } |
101 | | - }); |
| 103 | + this.lastChecked = this; |
| 104 | + }, |
| 105 | + }, |
| 106 | +}; |
| 107 | +// const checkboxes = document.querySelectorAll("input[type=checkbox]"); |
102 | 108 |
|
103 | | - //TODO = Find a way to reverse this in a way that when the shift key is pressed on a checked box, it will make them all unchecked |
104 | | - } |
105 | | - lastChecked = this; |
106 | | -} |
107 | | -checkboxes.forEach((checkbox) => |
108 | | - checkbox.addEventListener("click", checkShift) |
109 | | -); |
| 109 | +// let lastChecked; |
| 110 | +
|
| 111 | +// checkboxes.forEach((checkbox) => |
| 112 | +// checkbox.addEventListener("click", checkShift) |
| 113 | +// ); |
110 | 114 | </script> |
111 | 115 |
|
112 | 116 | <style scoped> |
|
0 commit comments