Tips for signaling to an AngularJS form that the input value has been altered

I developed a sign up form using angularjs. The submission process is functioning correctly. Now, I want to implement validation to check if the email provided is already registered. If it exists, display an error message indicating that the email is already in use. However, I am encountering an issue where even after the user changes the email address, the previously submitted email is still being used. How can I instruct angular to recognize when the input value has been modified and submit the newly entered values?

Here is my sign up form:

<div ng-controller="signupController">
<form ng-submit="doSignup()">
            <h2 class="form-signin-heading">Sign Up</h2>
            <div class="login-wrap">
                <input type="text" name="email" class="form-control" autofocus="" ng-model="formData.email">
                <span class="text-danger">{{ emailExistError }}</span>
                <input type="password" name="password" class="form-control" placeholder="Password" ng-model="formData.password">
                <input type="password" name="password_conf" class="form-control" placeholder="">
                <button class="btn btn-lg btn-login btn-block" type="submit">Sign Up</button>

            </div>
        </form>
</div>

Code snippet from app.js:

angular.module('myApp', ['ngRoute', 'ngSanitize'])
    .controller('mainController', function ($scope, $http) {

    })
    .controller('signupController', function ($scope, $http,$window) {

        $scope.formData = {};

        $scope.doSignup = function () {
            $http({
                method: 'post',
                url: 'signup.php',
                data: $.param($scope.formData),
                headers: {'Content-Type': 'application/x-www-form-urlencoded'}
            })
            .success(function (data) {

                $scope.login = data;

                if (data.status == 'ok') {
                    $('#successModal').modal('show');
                }
                else if (data.status == 'email exist'){
                    $scope.emailExistError = 'Email already exists. Please use a different email';
                }
                else {
                    $('#failedModal').modal('show');
                }

            })
        }
    })

Answer №1

experiment

$watch('email',function(currentValue,previousValue){
if(currentValue!=previousValue){
$scope.proceedRegistration();
}});

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

Ways to identify if a resize event was caused by the soft keyboard in a mobile browser

Many have debated the soft keyboard, but I am still searching for a suitable solution to my issue. I currently have a resize function like: $(window).resize(function() { ///do stuff }); My goal is to execute the 'stuff' in that function on ...

Leveraging the power of JavaScript to retrieve data from PHP/MySQL

Considering creating an Android app using Appcelerators Titanium application and have a question. The website for the app is built with PHP/MySQL, and I'm curious if it's possible to dynamically pull data from the database using JavaScript in Tit ...

Verify if there are DOM elements located within a DIV container, execute the functions associated with those elements sequentially

I am in the process of creating a game using HTML, CSS, and JavaScript. My focus right now is on manipulating DOM elements without relying on the canvas tag. The goal is to develop a pseudo graphical programming language, similar to the environment provide ...

swap between style sheets glitching

My website features two stylesheets, one for day mode and one for night mode. There is an image on the site that triggers a function with an onclick event to switch between the two stylesheets. However, when new visitors click the button for the first ti ...

What could be the reason behind Typescript's unexpected behavior when handling the severity prop in Material UI Alerts?

Trying to integrate Typescript into my react project and encountering a particular error: Type 'string' is not assignable to type 'Color | undefined'. The issue arises when I have the following setup... const foo = {stuff:"succes ...

Posting data using the form method="post" in Vue does not seem to be working

My goal is to create a website that allows users to reserve a seat using a specific password and time slot. I've set up a form where users can input the password and their name, then submit the form to make the reservation. However, I'm facing an ...

Having trouble with the Twitter share count URL - seeking out other options

Previously, I utilized the following Javascript function to retrieve the Twitter share count for a URL. Unfortunately, Twitter has discontinued providing the share count. Is there a more effective alternative available? // Twitter Shares Count $.getJSON ...

What is the best way in jQuery to pass an event to a parent anchor if necessary?

I'm working on a project in ClojureScript using jQuery, and I believe the answer should be applicable to both ClojureScript and JavaScript. My issue involves a helper function that creates an anchor element and then places an icon element inside it. ...

What is the best way to implement ng-model in conjunction with ng-repeat?

I created a form using ng-repeat, but I am struggling to incorporate ng-model into it. I attempted to use track by $index without success. While I found examples of using ng-model with values in an object, that's not what I'm looking for. I simp ...

What causes the difference between object[key] and Object.key in JavaScript?

After running the following code snippet, I observed that "typeof object[key]" is displaying as a number while "typeof object.key" is showing undefined. Can anyone explain why this unusual behavior is occurring? var object = {a:3,b:4}; for (var key in o ...

Troubleshooting: Missing Headers in AngularJS HTTP Requests

When I make a request using AngularJS like this: var config = { headers: { 'Authorization': 'somehash', 'Content-Type': 'application/json; charset=UTF-8' } }; $http.get('htt ...

Monitoring the actions that occur when my button is clicked using Firefox and Javascript

Whenever I click on a few new buttons that I've recently added, something weird is happening. The buttons are functioning correctly, but they keep scrolling the page back to the top. I suspect that there might be some interference from another part of ...

What is the best way to populate all text fields identified by xpath in Selenium using Python?

Seeking to streamline the form completion process with Selenium. I have programmed Selenium to locate elements by xpath. This means it automatically fills in fields that are of input type text. However, I am encountering a problem where Selenium only fil ...

What is the best method for transferring images to a node.js server using Axios?

Is there a method to utilize axios for sending an array of images or a single image to node? My current axios code (implemented in react js on the frontend): onFormSubmit(event){ event.preventDefault(); let payload = this.state; console.log(" ...

Utilize the splice function when resizing the window based on specific breakpoints

On a series of div elements, I have implemented some JS/jQuery code that organizes them by wrapping every three elements in a container with the class .each-row. <div class="element"></div> <div class="element"></div> <div class ...

Tips for invoking a url with JavaScript and retrieving the response back to JavaScript

I am trying to make a URL call from JavaScript with a single parameter, and the URL should respond to that specific request. Here is an example of the response format: {"success":true, "result": {"token":"4fc5ef2bd77a3","serverTime":1338371883,"expireT ...

Mastering Array Dispatch in VueJS

I've encountered an issue while trying to send an array of data to the backend. I attempted to include [] in the dispatch variables and on the backend, but it only captures the last data sent to the backend. My objective is to associate each data with ...

Incorporating AJAX and jQuery to dynamically update a numerical value

I need to update the content within a span class using jQuery. The first line of my jQuery code is functioning correctly as it adds a new notification to the list. However, the second line that should replace the existing number with @unseen_notifications. ...

No compatible version of Angular could be located

I'm receiving this error continuously. Any thoughts on why? $ bower install ng-roundabout --save bower cached git://github.com/angular/bower-angular-mocks.git#1.3.15 bower validate 1.3.15 against git://github.com/angular/bower-angular-moc ...

Utilize Angular 2 Form Elements Again

I'm currently in the process of working on a project with Angular and I want to make sure that my form components can be used for creating and updating entities seamlessly. Let's say I have a User entity stored on a remote API, and I have a form ...