AngularJS - real-time validation using the $valid property

I have implemented AngularJS to handle form validation and submission. The submit button is configured as follows:

<button type="submit" ng-disabled="btn" ng-click="submit(settings.$valid)" class="btn btn-primary">
  Submit
</button>

The button will be disabled if the form is invalid, and enabled once it becomes valid.

This is the code snippet in question:

$http.get("http://localhost:5000/settings").then(function(response){
    $scope.numberOfRows = response.data.numberOfRows
    console.log($scope.numberOfRows)
    if($scope.numberOfRows==0 && $scope.settings.$valid == false ){
        $scope.btn=true
    }else if($scope.numberOfRows==0 && $scope.settings.$valid == true){
        $scope.btn=false
    }

    if($scope.numberOfRows==1){
        $scope.btn=true
    }

})

My issue arises when numberOfRows equals 0 and the form is invalid, preventing me from submitting the form as desired.

However, upon successfully filling out the form and achieving a valid status, nothing seems to occur.

I am seeking assistance with this matter. Can you help me?

Answer №1

$http.fetch("http://localhost:5000/config").then(function(response){
    $scope.isTableAvailable= response.data.tableCount>0;
    $scope.configurations.$valid=$scope.isTableAvailable;
})

Now, embed the following code into your HTML file:

<button type="submit" ng-disabled="!configurations.$valid" ng-click="sendRequest()"
        class="btn btn-primary">
  Send
</button>

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 are the steps to integrate Webpack into an EJS Reactjs Express MongoDb application?

I have incorporated EJS, Express/NodeJs, and MongoDB into the project, along with ReactJs as an addition. My next step is to introduce Webpack for bundling both EJS and ReactJs files together. Although the end goal is to transition the p ...

The removal function in jQuery does not function as expected

I have a form where users can dynamically add fields to input information that will be inserted into a database. I'm able to add rows and insert data successfully, but I'm facing an issue with removing unwanted rows. When using the jQuery remove( ...

Problem with finding Rails controller file in .coffee extension

I recently started learning Rails and came across a file called welcome.js.coffee in the assets javascripts directory. # Place all the behaviors and hooks related to the matching controller here. # All this logic will automatically be available in applica ...

Adding the "disabled" attribute to a button using React

I am currently working on a project using Reactjs/nextjs and I need to add or remove the "disable" attribute. Can anyone assist me with this? Below is the code snippet I am working with: const handleSubmit = (e) => { e.preventDefault(); ...

The Angular script encounters a 404 error when attempting to load a Web API through the URL

My WebAPI method can be accessed here: http://localhost:50463/api/movies When I access this method from a browser, it loads perfectly without any issues. However, within my project (where the Web API is located), when I try to call the method from Angul ...

Are you familiar with the concept of personal $pockets?

Why does Angular's $q store everything under the $$state object? I thought that double dollar sign conventionally represents private in Angular, so it seems odd to me in this situation. Is there a mistake in how I've set up my promise? I'm ...

Development versions of npm libraries

Lately, I came across a library called react-3d-components that offers some d3 react components with basic charts. It's an impressive collection of components. However, when trying to access the source code due to incomplete documentation, I found my ...

Why Won't My PHP Form Submit on a Bootstrap Website?

I'm struggling with validation and need some assistance. I have a Bootstrap form embedded within an HTML page and a PHP script to handle the submission. However, whenever someone clicks on Submit, the page redirects to display my PHP code instead of a ...

Changing directions while the script is running

For my web site testing, I created a script using Tampermonkey that randomly browses the site and modifies parameters. Sometimes I need to navigate to a different page by either using window.location.replace(URL) or by clicking a button with the script l ...

Utilize JQuery to Extract HTML Elements

I'm working on developing a Chrome extension and one of my tasks is to extract specific text from the webpage I am currently visiting and store it in a variable. I have been attempting to achieve this using jQuery, however, none of the solutions I&apo ...

Is there a way for me to extract and showcase the initial 10 items bearing a particular class name from a different html document on my homepage?

I am looking to extract a list of movies from an HTML file titled "movies.html". The structure of the file is as follows: <div class="movie">Content 1</div> <div class="movie">Content 2</div> <div class=" ...

Encounter an error parsing the package.json file. Confirmed that it is valid JSON

As I embark on creating my very first yeoman generator, I have encountered an issue when running yo to initiate the project. The error message I am receiving is as follows: npm ERR! install Couldn't read dependencies npm ERR! Darwin 14.0.0 npm ERR! a ...

"Successfully uploading files with Ajax on Postman, however encountering issues when attempting to do so in

I am currently working on allowing specific users to upload videos to the API using Ajax. The process works smoothly in Postman, however, when attempting the same action from a web browser, I encounter a 500 Internal Server Error. Unfortunately, I do not ...

Struggling to fetch option value from a dynamic add/remove list using a combination of PHP, jQuery, and HTML5

Having trouble accessing and displaying values from a select list. Constructed an add/remove list functionality using JQuery but unable to showcase the values using foreach and for loops. Specifically trying to obtain $existing_mID[$j] values from the &apo ...

Troubleshooting a Custom Pipe Problem in Angular Material Drag and Drop

Currently, I am working on a project involving Angular Material Drag And Drop functionality. I have created a simplified example on StackBlitz which you can access through this link: here The project involves two lists - one containing pets and the other ...

Enhancing IntelliJ IDEA's autocomplete functionality with JavaScript libraries

Is there a way to add my custom JavaScript library to IntelliJ IDEA 10.5 or 11 for autocomplete functionality? I want to specify that IDEA should recognize and suggest auto-completions for objects from my library. While it sometimes works automatically, ...

What could be causing the NextJS query string to be undefined upon reloading the page?

I am currently working on a NextJS application where I have created a search results page that relies on a query parameter being passed. To grab the query string, I am using the next/router package. The issue I am facing is that after the initial load of t ...

Guide to creating a reminder feature in NestJS

In my NestJS project, I've created a POST API to add a Date object representing the date and time for sending notifications to a mobile app. Currently, I am working on checking which reminders have been reached for all users in order to trigger remin ...

Is there a way to determine if jQuery Mobile has already been loaded?

I am dynamically loading jqm and I'm trying to determine if it has been previously loaded in certain scenarios. Is there a method to check for the presence of jqm? ...

The functionality is not operating correctly on Internet Explorer

This code is functioning properly in Mozilla and Opera, but it is not working in IE. Any assistance on this issue would be greatly appreciated. The JavaScript is working fine, however, in IE 10 only the back panel is displayed. Thank you for your help. h ...