The ng disabled attribute is failing to update

I am working on a project that involves three different forms, each with its own unique name. Each form has required fields and there is a button that should be disabled until the current form is validated.

<ng-form="form0">
    //some required fields
    </ng-form>

    <ng-form="form1">
    //some required fields
    </ng-form>

    <ng-form="form2">
    //some required fields
    </ng-form>

<button class="btn btn-primary" ng-click="goToNextTab()" ng-disabled="{{'form'+currentIndex}}.$invalid" ng-show="currentIndex>=0&&currentIndex<3">Next</button>

Currently, the button is disabled initially and only becomes enabled after filling out form1. However, once I move to the next form, the button remains enabled even if the form isn't filled out.

$scope.goToNextTab=function()
    {
        $scope.currentIndex++;
    };

Answer №1

The variable ng-disabled is intended to be assigned either true or false, as it is a boolean value. However, you have mistakenly assigned it a string value.

Answer №2

observe the three structures and adjust the state of the button in this manner:

$scope.$watch('[form0.$valid, form1.$valid, form2.$valid]', function(forms) {
        var disabled = false;
        angular.forEach(forms, function(form){
            if(!form) disabled = true;
        });

        $scope.subDisable = disabled;
    }, true);

JSFIDDLE LINK

Answer №3

ng-disabled="'check'+currentIndex.$invalid"

Avoid using {{..}} within the code.

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

What is the best way to emphasize a specific data point within a chart created with chartjs, especially when the data is sourced from a JSON

// Here I am retrieving another set of data in JSON format from a PHP file $(document).ready(function () { showGraph(); }); function showGraph() { $.post("phpfile.php", function (data) { console.log(data); var name = []; v ...

Is the integer node reaching its limit?

Could someone guide me through this? $node -v v0.10.10 $ node > (10000000)>>1 5000000 > (100000000)>>1 50000000 > (1000000000)>>1 500000000 > (10000000000)>>1 705032704 Is it expected that 2^53 is the maximum integer ...

Verification of email address is not located in Clerk Auth, resulting in a 404 error message

For the past couple of days, I've been stuck on this issue and any help would be greatly appreciated. Thank you in advance! If necessary, I can provide additional code snippets. I am currently working on a project using nextjs with src. I'm try ...

"Troubleshooting 3D Models not appearing correctly in Mapbox when using Three.js

My issue lies in the inability to load any .gltf file, only a standard one. For further details, please continue reading. The map on my application showcases a 3D model indicated by the red arrow: https://i.sstatic.net/3Ce09.png The model is a GLTF file ...

Is it possible to retrieve the index of a chosen v-select option within Vuetify?

Exploring Vuetify for the first time, I'm encountering an issue with obtaining the index of a selected option on the v-select component. My goal is to populate a text field based on the option that is clicked once I have the index. I am fetching an ...

Press on a circle to adjust its size to fit the section or division

Is it possible to make a circle expand and fill the section/div when clicked? I want the circle to fill the screen upon clicking, and then have some text appear in its place. Before posting this, I searched on the web and came across this jsfiddle link. ...

The checkbox function is malfunctioning when integrated with JavaScript

I am facing an issue with my HTML checkbox that is supposed to select all checkboxes after clicking, but it doesn't seem to be working correctly. What could be causing this problem? Here is the JavaScript code I am using: <script language="JavaSc ...

What is the right way to choose the default option in a list?

I have 6 lists that I populate via a script. Using AngularJS, my HTML structure is as follows: <div class="advancedSearch hidden"> <div class="col-md-4 col-xs-12"> <select name="number" ng-model="Numbers" ng-change="listSearchC ...

Dealing with duplicate keys in an object while using AngularJS ng-repeat

My goal is to utilize the ng-repeat function to display the remaining data if the attribute is the same. To clarify, here is an example: Consider a JSON sample, which consists of an array of books: [{"Genre":"Sci-fic","Name":"Bookname1"}, {"Genre":"Sci- ...

Postman encountered a preflight failure on the Node API request

After calling the API from a browser, it successfully returns a correct response from the server: { "error": false, "message": "Hello World" }. However, when the same request is made using Postman, it results in an unexpected HTML content prompting to ena ...

Creating multiple child processes simultaneously can be achieved by spawning five child processes in parallel

My goal is to simultaneously run five spawn commands. I am passing five hls stream urls to the loop, and these streamlink commands are meant to record the video for 5 seconds before terminating those processes. I have attempted various async methods but a ...

The error encountered is: "TypeError: req.flash does not exist as a function in NodeJs

When it comes to working with Registration on a Site, the Validation process is key. In this case, mongoose models are being used for validation and an attempt is being made to utilize Flash to showcase error messages within the Form. However, there seems ...

Angular's routeProvider is failing to load the next template

I am struggling to implement a feature where each item in a list has a button that, when clicked, uses $routeProvider to navigate to a specific template. However, I keep encountering 404 errors when trying to access the page through the link. Any guidance ...

Tips for sending an array with all its elements from jQuery to PHP

Currently, I am attempting to transfer an array from jQuery to PHP. <input type="checkbox" id="name1" name="name[]" value="name1"> Name1 <input type="checkbox" id="name2" name="name[]" value="name2"> Name2 <input type="checkbox" id="name3" ...

Ajax GET Request causing page duplication issue

I've been diving into Ajax and following tutorials on W3Schools.com. My project involves using Ajax/PHP/MySQL to query a database based on button selections. I've successfully set up the request, but encountering an issue where clicking on a butt ...

Error: Attempting to access an undefined property ('useParams') which cannot be read

Hey there, I'm currently facing some challenges with the new react-router-dom v6. As I am still in the learning phase of this latest version, I could really use some assistance. import React from 'react' function Bookingscrren({match}) { ...

Transferring image Buffer over API for uploading to IPFS network

My attempt to upload an image to IPFS involves the following steps: I start by uploading the image from my web UI, converting it to a buffer in my Angular component. The next step is to send it via a put/post request (using HttpClient) to my NodeJS Expres ...

Enhance website security with X-ray standard user agent

Currently working on a Node.js application and utilizing the X-Ray library along with Request-X-Ray as a driver. I am curious to find out which user-agent X-Ray uses by default. Can anyone provide insights on this? ...

When using jQuery and AJAX together, it seems that the POST method is returning

Currently experimenting with Cloud9. The current project involves creating an image gallery. On the initial page: There are a few pictures representing various "categories". Clicking on one of these will take you to the next page showcasing albums fro ...

Creating a Dynamic Clear Button for a Text Area in Angular

Working on my Angular application, I have implemented a form with a textarea element. My goal is to incorporate a clear button inside the textarea element that should: Appear only when the textarea is focused Disappear when the textarea is out of focus ( ...