Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Javascript requires inputs to always have a label #57

Open
Nitrodist opened this issue May 4, 2022 · 2 comments
Open

Javascript requires inputs to always have a label #57

Nitrodist opened this issue May 4, 2022 · 2 comments
Assignees

Comments

@Nitrodist
Copy link

This line errors out when the input you've selected with a keypress does not have a corresponding label associated with it. See screenshot:

Screenshot

  function keypressFunction(evt) {
    evt = evt || window.event;
    var charCode = evt.keyCode || evt.which;
    var charStr = String.fromCharCode(charCode);
    if (!evt.target.labels) {
      return;
    }
    var label = evt.target.labels[0].textContent; // this line errors out when undefined.textContent is accessed
    var text = (evt.target.value + charStr).trim().replace("'", "\\\'");
    var action = "fill_in";
    var target = evt.target.labels[0].textContent;
    var options = ", with: '" + text + "'";

https://github.com/bullet-train-co/magic_test/blame/14747324998293e189956c1af15dc07d1e96686b/app/views/magic_test/_javascript_helpers.html#L44

Thoughts? A javascript warning that it doesn't exist would be a decent solution tbh - I only figured this out after I had the console open to figure out why the commands weren't persisting when I invoked flush in the terminal.

@Nitrodist
Copy link
Author

This still affects me, sadly 😂 But it is encouraging me to fix these labels, haha.

@gazayas
Copy link

gazayas commented Jul 10, 2023

I'm curious about this one, it looks like the following is in place to prevent the method from getting to that point in the code:

if (!evt.target.labels) {
  return;
}

Maybe we need to do something like !evt.target.labels.length instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants