Conflict with the prototype

Asked

Viewed 305 times

2

I’m having a doubt that’s ruining my nights.... I use Gento version 1.9.... more when I installed the module ecomdev to make the freight calculation on the product page it informs me an error when clicking to calculate freight...

Uncaught TypeError: undefined is not a function

 return elements.inject(initial, function(result, element) {
      if (!element.disabled && element.name) {
        key = element.name; value = $(element).getValue();
        if (value != null && element.type != 'file' && (element.type != 'submit' || (!submitted &&
            submit !== false && (!submit || key == submit) && (submitted = true)))) {
          result = accumulator(result, key, value);
        }
      }
      return result;
    });
  }
};

the error and informed on the excerpt key = element.name; value = $(element).getValue();

  • 2

    You can’t tell where the problem is in the code just by looking at the error message, you need to [Edit] the question and give more context. And when you talk about "prototype", you are talking about the library or the property of constructing functions?

  • the error is reported in the snippet "key = element.name; value = $(element). getValue();"

  • That one $(element).getValue(); is strange. You own jQuery on the page?

  • @Lucas he’s using the library prototype.

  • I am sending a print of the page with the http://sunsetimports.net.br/data/erro-prototype.PNGerror

  • I am sending a page print with the error [link]|(http://sunsetimports.net.br/data/erro-prototype.PNG) bold

  • @Alexproenca what gives you console.log(element, $(element)); inside that function, on the line before the error (inside the if)?

  • He tagged jQuery, I guess jquery is conflicting with the prototype or something.

  • he gives me anonymity function, he does not recognize the command sent from the module, but what is more strange Sergio, and that worked before stopped after I updated the Gento, until I tried to take the old prototype.js file and play in this new one but still he informs me the same error

  • Yeah, now the problem is where to use $(prototype) and where to change the $ for jQuery. -> http://stackoverflow.com/a/1401394/2256325

  • Wow and I’m new in the area... I’m getting beaten 2 days with this, :(

Show 6 more comments

1 answer

1

The Prototype and the jQuery both use the variable $ and are overlapping. I think in your case you are loading jQuery after Prototype.

The solution is to put the jQuery in conflict mode and use jQuery instead of $.

I suggest at the head of the page you have like this:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
var $j = jQuery.noConflict();
</script>
<script src="https://ajax.googleapis.com/ajax/libs/prototype/1.7.2.0/prototype.js"></script>

That way you free the dollar to the Prototype. If you keep making mistakes you have to go through the code and change the dollars that are in code jQuery for $j(etc...).

If you don’t know how... ask here. But you will need to provide the code, or a link to the page.

  • 1

    Thanks for the tip I’ll do here and later put the results ... Thanks for the force Sergio

Browser other questions tagged

You are not signed in. Login or sign up in order to post.