Questions tagged [javascript]

JavaScript (JS) is a client side script language which allows to interact with the user, control the browser, communicate asynchronously, and alter the document content that is displayed. By default Magento 1 comes with the prototype.js library and Magento 2 comes with jQuery. Use 'prototype-js' and 'jquery' tags for questions about those libraries.

1
vote
0answers
40 views

How to use javascript in ko template in magento 2?

I have a custom module which will overrride vendor\magento\module-checkout\view\frontend\web\template\shipping-address\shipping-method-item.html, here is the code <!-- /** * Copyright © Magento, ...
0
votes
0answers
11 views

The discount code can't be used automatically after a while?

I have set a discount code on the backend of the website for the convenience of customers. But every once in a while, the user can't use the discount code. I also retested, it is true, can not be used,...
0
votes
3answers
202 views

How to add custom js file in Magento 2 in custom theme without use module

I used custom theme in magento 2. I want to add custom js file for navigation in magento 2 but js file not work. I add js link in default_head_block.xml but a js doesn't work. <link src="js/menu....
0
votes
1answer
133 views

Magento 2 - Request from Javascript is returned with Status code 302

I´m sending a POST request with data via XMLHttpRequest. The response that I´m getting do have the status code 302. Javascript function: function createCSV() { let xhttp = new XMLHttpRequest(); ...
1
vote
0answers
90 views

Magento2: custom javascript not called when using with text/x-magento-init

In list.phtml (product listing) I am showing requistition lsit for every product using type="text/x-magento-init" in loop as: <script type="text/x-magento-init"> { "*": { "...
1
vote
1answer
484 views

Advanced js bundling

I try to optimize the bundles of magento with the information from devdocs . I try to do it on Magento 2.2.6 but the main issue is that after generating the bundles I get an error from the customer-...
0
votes
0answers
41 views

Magento 2 - checkout page loading but not stoping

when ever i click next for check out page some time still loading some times shows empty page How i can fix this....
0
votes
2answers
44 views

How to solve Unable to load CSS and JS after setup magento 2

My using Ubuntu 18 and apache2 I downloaded magento2 zip file and extract uploaded to my /var/www/html/ but always shows the above image I already setup htaccess file Already tried comments: ...
1
vote
1answer
876 views

JQuery how to remove tr in table which are display none in CSS [closed]

how to remove tr in a table which is display:none in CSS
0
votes
0answers
22 views

How to override the Thirdparty Extension adminhtml js file

Do I have to override js file from the app/code/Vendor/Module/view/adminhtml/we/js/widget.js file in magento2? Please suggest?
2
votes
2answers
815 views

Magento 2.2: Is it possible to use Vue.js in Magento?

If is possible, how can I integrate it in my custom module?
1
vote
0answers
30 views

How to add a configurable external JS with additional data- attributes via requirejs?

I was trying to add an external JS, say https://foo.bar/script.js (the url is configurable via config data) via requirejs, and I was successful so far. But then I realized that I would need to provide ...
1
vote
2answers
277 views

How to include custom JS to admin create new product in magento 2

I want to include custom JavaScript to create new product form. I already try with below way Using XML way. app/code/Namespace/Modulename/view/adminhtml/layout/index_index_add.xml <head> ...
0
votes
0answers
43 views

Product admin edit issue in magento 2

I am getting below error in console, when i try to edit product in admin Uncaught TypeError: data.some is not a function Referred below link and used that didn't solve my issue. Uncaught TypeError:...
0
votes
1answer
100 views

How to render HTML in x-magento-template?

I have used this blog https://webkul.com/blog/how-to-write-javascript-template-in-magento2/ to use x-magento-template. In this I can render data using such code: <%- data.name %> But it shows ...
1
vote
1answer
68 views

Buy On Amazon button

I want to add "Buy on Amazon" button on my product page. I was successful in adding it with this code: <a href="<?php echo $this->getProduct()->getamazonurl(); ?>"><img src="/...
1
vote
2answers
471 views

how to trigger click event in M2

In my header section I have user name and if user have access to different location then he has button saying click me. I want to send ajax call on this button. But JS is not working. Can anybody help ...
0
votes
1answer
24 views

The number of “Requests” is very large

I tested my website performance with Gtmetrix. I found that my website performance seems to be good, but the number of “Requests” is very large. I want to know if the impact of this problem is big? If ...
1
vote
2answers
123 views

Passing magento username and email variables into js script (Magento ver. 2.1.8)

<!-- Head --> <script src="https://wchat.freshchat.com/js/widget.js"></script> <!-- Head --> <script> window.fcWidget.init({ token: "WEB_CHAT_TOKEN", host: "...
0
votes
2answers
202 views

How to solve “One or more indexers are invalid. Make sure your Magento cron job is running” [duplicate]

My magento 2.2.1 website backend prompts "One or more indexers are invalid. Make sure your Magento cron job is running." How to solve this kind of error? Does it have a big impact?
1
vote
2answers
102 views

How to Load JS File at the Top?

I load my custom JavaScript file the following way: In: app/design/frontend/VENDOR/THEME/Magento_Theme/layout/default_head_blocks.xml I put: <?xml version="1.0"?> <page xmlns:xsi="http:/...
0
votes
0answers
111 views

Magento 2| How to add “Add to cart” Button functionality in jQuery?

I am adding "Add to cart" button functionality in jQuery function for calculated product quantity. I have add simple button yet. I have doing it as: My function is: $(document).ready(function(){ ...
2
votes
1answer
174 views

Why are browsers failing to load some static content?

Using Magento 2.2.6. I just installed a brand new install of 2.2.6 using Apache on OS X High Sierra, and with both Chrome and Firefox, after logging into the admin, the subnavigation does not work, ...
0
votes
0answers
12 views

Magento 2 opens the product page sometimes reminds error?

Magento 2 opens the product page and sometimes prompts [Identifier "" not exist.] This error sometimes does not prompt. Is this what is the reason?
1
vote
0answers
44 views

Extend a default JS component or Use Mixin

Which is better and recommended to use Extend a default js component as explained at https://devdocs.magento.com/guides/v2.1/javascript-dev-guide/javascript/custom_js.html#extend_js or to use Mixins ...
1
vote
0answers
170 views

Magento 2 Knockout Js Customer Name update issue after changing customer name

I am having strange issue. In header, along with Welcome message i am showing Customer full name. For that i am using knockout.js concept. <?php if($block->customerLoggedIn()): ?> <li ...
2
votes
0answers
99 views

Mini Cart Update issue

I am facing mini cart update issue - to replicate the issue you need to browse the site and add a product to the cart - then continue shopping. If you press checkout (instead of continue shopping) the ...
0
votes
1answer
356 views

Error message display using js in backend

I want to display an error message on the form/listing in magento 2 back-end. I know how to show those message using a controller. But how can i achieve same with JavaScript.
0
votes
1answer
75 views

Can't add custom script (leaflet) to Contact page

I'm trying to add a map in Contact page. In order to do that,I did the following: In file: app/design/frontend/MyCompany/MyTheme/Magento_Contact/layout/contact_index_index.xml I added: <page ...
0
votes
0answers
38 views

Minicart issue Magento 2 Safari only

We have - Magento 2.2.6 - Varnish, Redis Working on mobile and pc. But just not in Safari browser. In safari browser following issue: Go to product page Click 'add to cart' -> goes to cart ...
0
votes
0answers
92 views

UI Component - Disable Fieldset Collection

I want to figure out a way to take a <fieldset> collection (ex. customer's addresses), from a form ui component, and disable it due to a certain value of a field like a select drop down. The ...
0
votes
0answers
103 views

Magento 2: admin base URL for UI Components

There is BASE_URL variable on the adminhtml pages (see ./vendor/magento/module-backend/view/adminhtml/templates/page/js/require_js.phtml): <html> <head> <script> ...
0
votes
1answer
36 views

Modified JS file not changing Magento 2 Backend paging grid

I'm currently attempting to change the "sizes.js" file using a child theme in adminhtml. This is with the "Commerce" version of Magento 2.2.5. As we have a large number of customers and orders. What ...
0
votes
0answers
19 views

Loading default image failing with quote in name

I have several product in my store. Some of them have no image and have quote in the name Example of name: My product "a detail" This is causing this issue : SyntaxError: JSON.parse: ...
2
votes
1answer
217 views

Upgrade to 2.2.6 missing static JS files

When I upgraded my Magento 2.2.2 to 2.2.6. I got one critical error in pub/static missing one file named trim-input.js "pub/static/version1540806968/frontend/{...}/{...}/pl_PL/mage/trim-input.js" ...
0
votes
1answer
368 views

Override Magento UI js file

How can I override this file on my theme? /vendor/magento/module-ui/view/frontend/web/js/view/messages.js I'm a newbie to M2
1
vote
4answers
481 views

I want to translate “Buy” and “save” word in tier_price.phtml file. magento 2

I want to translate "Buy" and "Save" word in tier_price.phtml file.I have added the word in translation csv file but it is not working form me. Refer screenshot PATH : vendor/magento/module-...
1
vote
1answer
51 views

Frontend suddenly showing code

We now have 'code' on our frontend. See image. Please advise
0
votes
2answers
162 views

Magento 2: Override js in custom module doesn't work?

I'm trying to override js in custom module, but that module which i want to override is already override some js from magento_checkout. And seem like it doesn't work :( Here is how i did: That ...
2
votes
1answer
401 views

Magento 2: get current store view in JS

I need to get current store view code in JS component to compose i18n-compatible route to the REST API operation: define( ["jquery", "ko", "uiComponent", "mage/translate"], function ($, ko, ...
1
vote
0answers
231 views

display a popup once per day!

this code is to display a pop up once per day. But I'm having trouble making it responsive, and it seems that it shows once a lifetime... Also if I put it in 3 different pages, and it only shows up ...
0
votes
1answer
16 views

Sometimes getting cannot read property issue after page load due to which some functionality affected

On the entire website(homepage, category page etc) sometimes I'm getting "cannot read property timepicker" issue due to which some feature like "Add To Quote" functionality affected & instead of "...
1
vote
1answer
398 views

Extend Swatch rendered js file

How to extend the Swatch rendered js file in my custom module? I have override the phtml template files. <script type="text/x-magento-init"> { "[data-role=swatch-option-<?= /* @...
0
votes
0answers
60 views

Load ajax after using observer

I have added this JS code inside catalog-add-to-cart.js : var popup = $('<div class="add-to-cart-dialog ajoutPanierModal"/>').html('<span>Le produit a été ajouté au panier.</span>')...
0
votes
2answers
482 views

How to get values passed from phtml in js magento 2?

I have passed two variables in my phtml to js file as below <script type="text/x-magento-init"> { ".slider-gallery": { "slickSlider": { "...
1
vote
1answer
254 views

Magento 2 jsonParse() does not receive data, Unexpected token '

I'm creating a js template in Magento 2. When I call js, I get an Uncaught SyntaxError: Unexpected token 'in JSON at position 96. Why jsonParse () does not get the value? Can somebody help me? file ....
1
vote
1answer
77 views

How To Debug Custom Feedback Form Sidebar Slider JavaScript Error?

I'm trying to create a Feedback form Sidebar slider. Workout: step 1: C:\wamp\www\magento\app\design\frontend\default\theme327k\layout\local.xml <?xml version="1.0" encoding="UTF-8"?> <...
0
votes
2answers
42 views

Magento 2.2.5 custom theme js errors

I created a custom child theme for luma and it works fine. But when I extend the layout for Magento_Theme I start getting all kinds of javascript errors which are random, sometimes they don't appear ...
0
votes
0answers
198 views

Magento 2 Cannot read property get of undefined

When this module is disabled 'MagePal_GoogleTagManager' => 1 the error dissapears. However I need the module to be enabled.
0
votes
1answer
322 views

Magento 2 How to add custom validation rules and apply them?

I'm trying to modify some validation rules for the State input in shipping address. I want to add an error message if user selects 'Texas'. I created a mixin for Magento_Ui/js/lib/validation/rules in ...