magic_test icon indicating copy to clipboard operation
magic_test copied to clipboard

Javascript requires inputs to always have a label

Open Nitrodist opened this issue 2 years ago • 2 comments

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 avatar May 04 '22 19:05 Nitrodist

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

Nitrodist avatar Jan 06 '23 06:01 Nitrodist

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.

gazayas avatar Jul 10 '23 05:07 gazayas