Fixing bug in a script that involves identifying steps using Material Steppers

I am currently developing a small AngularJS application that utilizes Material Steppers for navigation.

In order to achieve a specific functionality, I need to ensure that items selected from two different sections of the page belong to category ID 1. The function should only return true if items from both sections meet this criteria.

The selection process in section A must trigger a change in the variable this.isTriggerB, but this change should occur only after selecting items from section A:

class Controller {
  constructor($mdStepper) {
    this.isTriggerA = false;
    this.isTriggerB = false;
    this.clickedStepNumber = 0;

    getCurrentStep() {
      this.steppers = this.$mdStepper('stepper');
      const steps = this.steppers.steps;
      steps.forEach((el, index) => {
        let step = this.steppers.steps[index];
        if (step.isClicked()) {
          this.clickedStepNumber = step.stepNumber;
        }
      });
    }

    checkCategory() {
      this.getCurrentStep();
      if (this.filter.provider) {
        let categoryID = parseInt(this.filter.category.id, 10);

        console.log('Cid: ' + categoryID);

        if (categoryID !== 1) {
          this.isTestPassed = false;
        } else {
          if (parseInt(this.clickedStepNumber, 10 === 1)) {
            this.isTriggerA = true;
            console.log('Step: ' + this.clickedStepNumber);
            console.log("A1: " + this.isTriggerA);
            console.log("B1: " + this.isTriggerB);
          }

          if (parseInt(this.clickedStepNumber, 10 === 2)) {
            this.isTriggerB = true;
            console.log('Step: ' + this.clickedStepNumber);
            console.log("A2: " + this.isTriggerA);
            console.log("B2: " + this.isTriggerB);
          }

          if (this.isTriggerA === true && this.isTriggerB === true) {
            this.isTestPassed = true;
          } else {
            this.isTestPassed = false;
          }
        }
      }
    }
  }

The execution flow should handle the two cases (steps) separately without entering into unwanted conditions.

Can you help me identify any errors in my approach?

Answer №1

Reposition the banana:

    if (categoryID !== 1) {
      this.isTestPassed = false;
    } else {
      if (parseInt(this.clickedStepNumber, 10) === 1) {
        this.isTriggerA = true;
        console.log('Step: ' + this.clickedStepNumber);
        console.log("A1: " + this.isTriggerA);
        console.log("B1: " + this.isTriggerB);
      }

      if (parseInt(this.clickedStepNumber, 10) === 2) {
        this.isTriggerB= true;
        console.log('Step: ' + this.clickedStepNumber);
        console.log("A2: " + this.isTriggerA);
        console.log("B2: " + this.isTriggerB);
      }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue encountered when making a request from React to Express without using Create React App (CRA)

import React,{Component} from 'react'; import '../styles/App.css'; class App extends Component{ constructor() { super(); this.state = { products: [] }; } componentDidMount() { fetch('http://localhost:40 ...

What is the most efficient way to update several documents at once by referencing the value of a nested property?

Looking to update documents based on nested property values? Let's take an example document: { "_id": "61e3050a465c380aec9f56a1", "name": "John Doe", "status": "pending", ...

Displaying a Dynamic Loading Animation While Making an AJAX Call with jQuery

When a user clicks on the active status button, it should switch to inactive with a red color, and vice versa. Currently, I can update my status in the backend, but I have to refresh the page to see the changes every time! My requirement is that during t ...

Having trouble fetching JSON data using Ajax in Flask

I am working on creating a straightforward web application for displaying logs. The backend is powered by Python 3.4 and Flask, while the frontend consists of a simple web form with AJAX integration. Flask: import json from flask import Flask, jsonify, r ...

Determining the precise coordinates of each sphere to construct a larger sphere comprised entirely of interconnected spheres

I am currently working on recreating an atom using THREE.js and I have encountered my first hurdle. Each type of atom contains varying numbers of Protons and Neutrons, so I am trying to figure out a way to automatically position them without colliding with ...

Tips for defining a state variable as a specific Type in Typescript

I am working with the following type: export type AVAILABLE_API_STATUS = | "Created" | "Process" | "Analysis" | "Refused"; I am wondering how to create a state using this type. I attempted the following: co ...

Transmit information from javascript to the server

I am currently working on an ASP.NET MVC web application and have a query: If I have a strongly typed view and I submit it, the object (of the strongly type) will be filled and sent to the server. But what if one of the properties of the strongly typed i ...

When the onChange event is triggered, the current value in my text input field disappears in React

Just starting out with Reactjs and I'm working on creating a page where users can edit their own posts. Currently, when I try to modify the existing text in the text input, the form gets cleared and the user has to re-enter the data. This is not the b ...

JavaScript FF IE Update + problem with messaging script

I am currently using an ajax_update script that updates file.php every 60 seconds. The output of file.php after updating a table is as follows: <div id='message' style="display: none;"> <span>Hey, <b><? echo $userid; ?&g ...

What is the best way to ensure that my multiple choice code in CSS & JS only allows for the selection of one option at a time? Currently, I am able

I'm currently facing a small issue that I believe has a simple solution. My knowledge of Javascript is limited, but I am eager to improve my skills in coding for more visually appealing websites. My problem lies in the code snippet below, where I am ...

The error message "Ionic React Overmind encountered issues with updating the state of an unmounted component" is preventing the React application

Utilizing Overmind in combination with Ionic React: Tab1: const { count } = useAppState() const { increaseCount } = useActions() return <IonPage> <IonContent> <IonRouterLink routerLink='/tab1/page1'>1. Navigate to anothe ...

The Angular directive ng-if does not function properly when trying to evaluate if array[0] is equal to the string value 'Value'

In my code, I want to ensure that the icon is only visible if the value at array index 0 is equal to 'Value': HTML <ion-icon *ngIf="allFamily[0] === 'Value'" class="checkas" name="checkmark"></ion-icon> TS allFamily = [ ...

Is there a way to set a value for an attribute in a form post submit button click?

I need to update the value of a form when the user selects "null" <form name="myForm" action="formProcess.php" method='post' onSubmit="return validateForm()"> <label for="venue">Venue:</label> <select name="venue"> ...

What are the steps for building modules using Vuex and fetching data using mapState()?

I've been experimenting with separating my Vuex code into modules, but I'm having trouble retrieving data using mapState(). What's the most effective approach for creating modules and utilizing mapping? Here's the structure of my stor ...

Struggling to synchronize the newly updated Products List array in zustand?

Let me clarify the scenario I am dealing with so you can grasp it better. I have a Cart and various Products. When a user adds the product (product_id = 1) twice to the cart with the same options (red, xl), I increase the quantity of that item. However, i ...

JavaScript - A simple way to retrieve the dimensions of an image consistently

I'm currently working on a piece of Jquery code that is designed to display an image fitting within the screen's dimensions. These images are generated dynamically as needed. However, I am facing an issue where the height and width of the image a ...

Utilizing the JSON.parse method in JavaScript in conjunction with an Ajax request while incorporating the escape character "\n" for new line functionality

https://jsbin.com/zuhatujoqo/1/edit?js,console Edit: json file has this line: {"pd":"ciao \\n ste"} I need to retrieve a valid JSON file through an ajax call. Then parse the result using JSON.parse. I'm confused about the behavior of t ...

Error Encountered: Unresolved ReferenceError in VUE 3 Component while updating modelValue

I am encountering the error "Uncaught ReferenceError: comp1 is not defined" when emitting "update:modelValue" from the component. Interestingly, this issue only occurs after I have built the project, not during development. Parent: <script setup> i ...

The onClick event handler is triggered on page load instead of waiting for a click

Recently delving into React, I encountered an issue while attempting to call a function set as a prop. Take a look at my component below: class SamplesInnerLrg extends Component { playSampleAction(sample,sampleId) { console.log(sample); } ...

Fixing the errors outlined below

After integrating the spectrum color picker, I'm currently working on resolving the JSLint errors that have appeared. There are two specific types of errors that I'm struggling to rectify. Here they are: Unexpected '~' Unexpect ...