3

I'm trying to debug a js file in Magento 2. And I don't know how to do that. I've try console.log('something in here') but doesn't work, I've clear cache as well.

Here is my problem: I've 3 checkboxes here, and they count in that"input hidden" in the image below. enter image description here

So when I click on the checkbox to turn off, it counts down 1 (see the image below). It works perfectly til here. enter image description here

But when I click on the checkbox again. It should count up 1 right, but it doesn't. I don't know where is wrong in my code.

Here is my js file named assign-slide.js (this js is following assign-product.js):

C:\xampp\htdocs\magento\vendor\magento\module-catalog\view\adminhtml\web\catalog\category\assign-products.js

/**
* Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
/* global ,ドル $H */
define([
 'mage/adminhtml/grid'
], function () {
 'use strict';
 return {
 assignSlide: function(config){
 var selectedSlide = config.selectedSlide,
 bannerSlide = $H(selectedSlide),
 gridJsObject = window[config.gridJsObjectName],
 tabIndex = 1000;
 $('in_banner_slide').value = Object.toJSON(bannerSlide);
 /**
 * Register Banner Slide
 *
 * @param {Object} grid
 * @param {Object} element
 * @param {Boolean} checked
 */
 function registerBannerSlide(grid, element, checked) {
 if (checked) {
 if (element.positionElement) {
 element.positionElement.disabled = false;
 bannerSlide.set(element.value, element.positionElement.value);
 }
 } else {
 if (element.positionElement) {
 element.positionElement.disabled = true;
 }
 bannerSlide.unset(element.value);
 }
 $('in_banner_slide').value = Object.toJSON(bannerSlide);
 grid.reloadParams = {
 'selected_slide[]': bannerSlide.keys()
 };
 }
 /**
 * Click on Slide row
 *
 * @param {Object} grid
 * @param {String} event
 */
 function bannerSlideRowClick(grid, event) {
 var trElement = Event.findElement(event, 'tr'),
 isInput = Event.element(event).tagName === 'INPUT',
 checked = false,
 checkbox = null;
 if (trElement) {
 checkbox = Element.getElementsBySelector(trElement, 'input');
 if (checkbox[0]) {
 checked = isInput ? checkbox[0].checked : !checkbox[0].checked;
 gridJsObject.setCheckboxChecked(checkbox[0], checked);
 }
 }
 }
 /**
 * Change Slide position
 *
 * @param {String} event
 */
 function positionChange(event) {
 var element = Event.element(event);
 if (element && element.checkboxElement && element.checkboxElement.checked) {
 bannerSlide.set(element.checkboxElement.value, element.value);
 $('in_banner_slide').value = Object.toJSON(bannerSlide);
 }
 }
 /**
 * Initialize Banner Slide row
 *
 * @param {Object} grid
 * @param {String} row
 */
 function bannerSlideRowInit(grid, row) {
 var checkbox = $(row).getElementsByClassName('checkbox')[0],
 position = $(row).getElementsByClassName('input-text')[0];
 if (checkbox && position) {
 checkbox.positionElement = position;
 position.checkboxElement = checkbox;
 position.disabled = !checkbox.checked;
 position.tabIndex = tabIndex++;
 Event.observe(position, 'keyup', positionChange);
 }
 }
 gridJsObject.rowClickCallback = bannerSlideRowClick;
 gridJsObject.initRowCallback = bannerSlideRowInit;
 gridJsObject.checkboxCheckCallback = registerBannerSlide;
 if (gridJsObject.rows) {
 gridJsObject.rows.each(function (row) {
 bannerSlideRowInit(gridJsObject, row);
 });
 }
 }};
});

EDIT 1:

So I found the way to debugging with console.log if you go to pub/static../your_js_file_that_you_want_to_console_log.js and put console.log in there and clear cache also Ctrl + F5 in your browser so it clear your browser cache as well.

But my problem with js still there.

Ghulam.M
9738 silver badges25 bronze badges
asked Aug 11, 2018 at 1:49
2
  • Please share your full code. Commented Aug 11, 2018 at 9:37
  • 1
    Oh, i've a bigger problem now, please check. magento.stackexchange.com/questions/238050/… Thanks :) Commented Aug 11, 2018 at 9:43

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.