invoking click() Method on a checkbox, checks it...but also throws an error #10587
Replies: 1 comment
-
If you log the wrapper element to the console, you will find that it's not the div. The Sidenote: You say they have So consequently, the What you actually need to use, I think, is
Also, I would argue your approach itself is usually considered an anti-pattern. A better way to solve this is to have the label wrap the input (or providing a proper <div class="cb-container p-2 d-flex flex-wrap justify-content-center align-items-start">
<div
v-for="dev in all_developers"
:key="dev.id"
:value="dev.id"
class="cb-label-holder m-2 p-2 d-flex justify-content-between align-items-center">
<label>
<input type="checkbox" :value="dev.id"> {{ dev.name }}
</label>
</div>
</div> Sidenote: This is not a Typescript error, it's a Javascript runtime error thrown in the browser - so your attempts to solve this by adding types in different ways would do nothing to solve this. |
Beta Was this translation helpful? Give feedback.
-
Part of my components template looks like this:
As you can see, there are divs
.cb-label-holder
that contain a checkbox and a corresponding label.When clicked on,
toggleCheckbox
does this:Both the checkbox and label have
pointer-events: none;
When clicked on the cb-label-holder, the containing checkbox gets checked, but this error is thrown:
"Cannot read properties of null (reading 'click')
TypeError: Cannot read properties of null (reading 'click')"
And i dont know why. What did i miss?
This is what i tried so far:
Defining cb in an onother way:
const cb = wrapper.querySelector("input") as HTMLElement;
const cb = <HTMLInputElement>wrapper.querySelector("input");
const cb = <HTMLElement>wrapper.querySelector("input");
const cb = <HTMLInputElement>wrapper.querySelector("input");
In all those cases, the actual selecting of the checkboxes happens, but the error occurs.
By the way, when using those versions, i get instantly another error saying:
"137:0 error Parsing error: Unexpected token. Did you mean
{'}'}
or}
?"I cannot do anything with that error. What does it mean?
Beta Was this translation helpful? Give feedback.
All reactions