prototypejs / prototype

Prototype JavaScript framework
http://prototypejs.org/
Other
3.53k stars 639 forks source link

Uncaught TypeError: $(...).getValue is not a function #342

Closed tbtalbottjr closed 5 years ago

tbtalbottjr commented 5 years ago

We recently moved an old codebase from Prototype 1.7 to 1.7.1 because we are about to embark on an iterative rewrite using vue.js. Moving to 1.7.1 fixed some incompatibility issues that I don't recall off the top of my head. But we noticed that since moving to 1.7.1 we are getting the following error when used in mobile Safari or mobile Chrome:

application.js:2001 Uncaught TypeError: $(...).getValue is not a function
    at Object.set_criteria (application.js:2001)

where application.js has:

  set_criteria: function(num) {
    console.log('search_select_' + num)
    console.log($('search_select_' + num))
    var uid     = $('search_select_' + num).readAttribute("_uid");
    var val     = $('search_select_' + num).getValue();
    ...

This error also occurs using 1.7.2 and 1.7.3. The error does not occur in either desktop browser.

We are reverting to 1.7 for now until we can figure out this problem and will try to create a simplified repro case when I get a chance, but was wondering if this is a known issue. I can't find anything on it, so I wonder if there is a different incompatibility with another JS library we are using.

jwestbrook commented 5 years ago

I see the console.log calls what do they show in the console?

Typically if an element with the id does not exist then $() will return null and $().getValue() will not be a function.

Also I think if the element you are attempting to run .getValue() on is not a normal form element, or not a descendent of a <form> element the .getValue() method will not exist on the element.

tbtalbottjr commented 5 years ago

Thanks for the reply

The log shows the <select> element that we are expecting. I thought the same thing.

Right now we are going down the path of suspecting some other JS library conflict since an isolated test case seems to be working. I will close if we are able to determine why it is happening and why only on mobile and if it isn't a problem with 1.7.1+.

tbtalbottjr commented 5 years ago

We found that the problem was being caused by our own JS that was defining:

   var Node = {
      ...
   }

This apparently conflicts with code in 1.7.1+, but only in mobile browsers. :/

Renaming this (or namespacing it) solves the problem. I can close this unless you feel it is worth investigating whether it makes sense for Node to be left vulnerable in this case.

Thanks.

jwestbrook commented 5 years ago

I'm guessing that your Node is in the global space - so with the DOM rewrite in 1.7.1 Prototype uses a variable Node in the global space as well as a general definition of a DOM node.

I'll open a specific issue that references this issue so you can close it.

tbtalbottjr commented 5 years ago

Yes, that is correct.

Closing.