Disabling functionality is not working properly when multiple expressions are added

One specific scenario involves using a radio button for selecting options and requiring users to confirm their selection using the JavaScript confirm method before enabling the next button. Take a look at the following code:

HTML

  <body ng-controller="MainCtrl">
  <div ng-repeat="person in names">

    <input class="d-radio__input" ng-model="$parent.selectedCustomer" type="radio" ng-value="person" value="{{person.name}}" name="radio" ng-click="confirm()" required /> {{person.name}}

  </div>
  <button>Back</button>
  <button ng-click="next()" ng-disabled="selectedCustomer =='' && confirmation == 0 ">Next</button>
</body>

Javascript

    app.controller('MainCtrl', function($scope) {
  $scope.selectedCustomer ='';
  $scope.confirmation=0;
  $scope.names = [{name:"Mayur"},{name:"Sameer"}];

                $scope.next = function () {
                    $scope.navigator =  $scope.navigator + 1 ;
                    console.log($scope.navigator)
                };
                $scope.confirm = function (location) {
                    var r = confirm("Click Ok to continue the offboarding process for (" + $scope.selectedCustomer.customerName + ")");
                    if (r === true) {
                        $scope.confirmation = 1;
                        console.log($scope.confirmation );
                    } else {
                        $scope.confirmation = 0;
                        console.log($scope.confirmation );
                    }
                }
});

After selecting a name, the next button gets enabled immediately regardless of the user's choice in the confirmation dialog. However, the issue arises when trying to evaluate multiple conditions for ng-disabled. If you have any suggestions or solutions, please let me know.

View the working code on Plunker

Answer №1

According to the feedback, the ng-disabled attribute is preventing the button from being clicked, but only if both conditions are met due to the use of AND operator. To fix this, replace && with || to use the OR operator as demonstrated in the following code snippet:

<button ng-click="next()" ng-disabled="selectedCustomer == '' ||  !confirmation ">Next</button>

http://plnkr.co/edit/pGTuuE9RyGz7WOKSnClG?p=preview

Answer №2

It seems like this meets your needs.

var app =angular.module('app' ,[])
app.controller('MainCtrl', function($scope) {
  $scope.selectedCustomer ='';
  $scope.confirmation=0;
  $scope.names = [{name:"Mayur"},{name:"Sameer"}];

                $scope.next = function () {
                    $scope.navigator =  $scope.navigator + 1 ;
                    console.log($scope.navigator)
                };
                $scope.confirm = function (location) {
                    var r = confirm("Click Ok to continue the offboarding process for (" + $scope.selectedCustomer.customerName + ")");
                    if (r === true) {
                        $scope.confirmation = 1;
                        console.log($scope.confirmation );
                    } else {
                        $scope.confirmation = 0;
                        console.log($scope.confirmation );
                    }
                }
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app='app' ng-controller="MainCtrl">
  <div ng-repeat="person in names">

    <input class="d-radio__input" ng-model="$parent.selectedCustomer" type="radio" ng-value="person" value="{{person.name}}" name="radio" ng-click="confirm()" required /> {{person.name}}

  </div>
  <button>Back</button>
  <button ng-click="next()" ng-disabled="selectedCustomer =='' || confirmation == 0 ">Next</button>
</body>

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

Are you interested in using jQuery and/or AJAX to retrieve the latest images from a website?

I had to utilize a Wikipedia API in order to retrieve images from the New Jersey website, and I devised two methods to carry out similar tasks. The initial approach involved using JSON, but it ended up pulling the entire page content. <script type="tex ...

Proper approach for mapping JSON data to a table using the Fetch API in a React.js application

Struggling to map some elements of JSON to a Table in Customers.jsx, but can't seem to figure out the correct way. How do I properly insert my Fetch Method into Customers.jsx? Specifically managing the renderBody part and the bodyData={/The JsonData/} ...

Improving HTML coding with a more effective alternative to document.write()

Looking at the setup of my website, I have a menu button and comments section that need to appear on every page. Instead of manually adding this code to each HTML file, I decided to streamline the process by using a JavaScript file that generates all of th ...

How can I create a script in Discord.js that automatically sends users their information upon joining the server?

I'm currently working on developing a code that automatically sends the user's avatar, username, ID, account creation date, server join date, and status when they join The structure of the code looks something like this: module.exports = (Discor ...

What is the method for applying the action (hide) to every table cell that doesn't include a specific string in its ID?

I have a table with cells containing unique IDs such as "2012-01-01_841241" that include a date and a number. My goal is to filter the table to only display three specific numbers by sending a request and receiving those numbers. Is there a more efficien ...

Guide on utilizing fragment shaders from glslsandbox.com

I'm interested in experimenting with ShaderMaterial from Three.js, but I am not familiar with the OpenGL Shading Language. When I try to use the fragment shader code from the website mentioned above, I encounter a number of errors. I'm unsure if ...

Upon refreshing the page in Javascript, the element mysteriously vanishes without a trace

After implementing a function that should display "barProgress25" and hide "barProgress0" when a button is clicked, I encountered an issue. Upon clicking the button, the function works as intended but upon page refresh, "barProgres ...

What is the best way to calculate the days, exact hours, and exact minutes between two dates using JavaScript?

I need assistance with calculating the number of days, hours, and minutes between a start date time and an end time. For example: Start Date Time = "09-06-2017 10:30" End Date Time = "10-06-2017 11:45" I am looking for the result to be 1 day, 1 ...

Is it possible to access the chrome://webrtc-internals/ variables through an API in JavaScript?

I couldn't find any information about how to access the logged variables in chrome://webrtc-internals/ on google. There is not even a description of the graphs available there. I am specifically interested in packetsLost, googCurrentDelayMs, and goo ...

Issue: nodebuffer is incompatible with this platform

Currently, I am attempting to utilize the Shpjs package in order to import a Shape file onto a Leaflet map. According to the Shpjs documentation: shpjs Below is the code snippet I am working with: const [geoData, setGeoData] = useState(null); //stat ...

Pressing the CTRL key and then the PLUS key simultaneously activates the zoom in

Is there a way to capture Ctrl + + / Ctrl + - events in Firefox using the following code: window.onkeydown = function(event) { if(event.ctrlKey && event.keyCode == 61) CtrlPlus(); if(event.ctrlKey && event.keyCode == 169) // or ...

What steps can be taken to retrieve data from a database table using JavaScript?

I am encountering a very peculiar issue. The values that I need are visible when I receive them as a message from the server-web console. However, when I try to retrieve them using a for loop, I encounter an error 05-22 18:58:23.203: I/Web Console(29392): ...

Is there a problem triggering a link click with another click in jquery?

I'm currently facing a situation where I have implemented a simple tab menu from a resource found here. <ul class="tabs"> <li><a href="#tab1">tab1</a></li> <li><a id="myprofile" href="#tab2">tab2</a>< ...

Continue iterating using (forEach, map,...) until the object (children) has no more elements

I need to disable the active status for all elements within my object structure. Here is an example of my object: const obj = { name: 'obj1' , ative: true , children: [ { name: 'obj2' , ative: true , children: ...

Losing authentication token when refreshing with Nuxt asyncData and Axios

While testing a get API that retrieves an array of mail data through Postman, everything seems to be working smoothly. However, when I implement the asyncData method to fetch the array in my code, it only works once. Upon page refresh, I encounter a 401 er ...

Can an identification be included in a label element?

My inquiry is as follows: <label for="gender" class="error">Choose</label> I am interested in dynamically adding an id attribute to the above line using jQuery or JavaScript, resulting in the following html: <label for="gender" class="err ...

Can you restrict the selection of text to only the current element?

<div class="container"> <div class="item1">text text text in div element 1</div> <div class="item2">text text text in div element 2</div> </div> Is there a way using HTML nodes, CSS, or JavaScript to restrict the select ...

Chronological Overview (Highcharts)

Can you customize a timeline in Highcharts to resemble the image? https://i.sstatic.net/5Lipu.png I have a functional example of the timeline I desire, but the color coding and filtering aspects are challenging for me. I am attempting to apply a filter th ...

Setting a setTimeout function for a Vue function

Can clearTimeout be used for a setTimeout function assigned to a Vue Method? If yes, how can it be accomplished? methods: { timeoutController() { setTimeout(function() { this.controllerShown = false; }, 3000); ...

Feeling puzzled about the next() function in Node.js?

https://github.com/hwz/chirp/blob/master/module-5/completed/routes/api.js function isAuthenticated (req, res, next) { // If the user is authenticated in the session, call the next() to proceed to the next request handler // Passport adds this met ...