Angular JS Form's Pristine feature is malfunctioning when attempting to reset

I implemented a login form on my website. After submitting the form, I clear it and set it to Pristine mode. However, the error message still persists.

Below is the code for my form:

<form name="loginForm" ng-submit="loginForm.$valid && login(user)" novalidate style="position: relative">
    <div class="log-input-frm mdl-textfield mdl-js-textfield mdl-textfield--floating-label textfield-demo">
        <div class="col-sm-12 f_name">
            <input ng-model="user.username" name="username" type="email" placeholder="Email address" required="">
            <div ng-show="loginForm.$submitted || loginForm.username.$touched" ng-model="loginForm.username">
                <span ng-show="loginForm.username.$error.required" class="text-danger">Please enter email address.</span>
                <span ng-show="loginForm.username.$error.email" class="text-danger">Please enter valid email address.</span>
            </div>
        </div>
    </div>
    <div class="log-input-frm mdl-textfield mdl-js-textfield mdl-textfield--floating-label textfield-demo">
        <div class="col-sm-12 f_name">
            <input ng-model="user.password" name="password" type="password" placeholder="Password" required="">
            <div ng-show="loginForm.$submitted || loginForm.password.$touched" ng-model="loginForm.password">
                <span ng-show="loginForm.password.$error.required" class="text-danger">Please enter password.</span>
            </div>
        </div>
    </div>
    <div class="buttons">
        <span class="signup pull-left">
            <a ui-sref="forgotpassword">Forgot password</a>
        </span>
        <div class="link">
            <div class="link" style="padding-bottom:0;">
                <md-button type="submit" class="md-raised primary" > Login </md-button>
            </div>
        </div>
    </div>
</form>

I also have controller code to reset the form and set it back to pristine mode:

$scope.loginForm.$setPristine();
$scope.loginForm.$setUntouched();
$scope.user = {};

Despite this, the error message still remains visible. Can you help me figure out what went wrong?

Answer №1

The issue was successfully resolved by implementing a timeout function.

$scope.user = {};
$timeout(function () {
    $scope.loginForm.$setPristine();
    $scope.loginForm.$setUntouched();
    $scope.loginForm.$submitted = false;
});

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

The page is having trouble loading images

My goal is to display sliding images in a web application using Bootstrap carousel. The images are fetched from the backend and stored in the 'images' state. Below is the JSON format of the data that is retrieved: images:[ { SNO:'1', NA ...

JavaScript if else statement with 3 different scenarios

I'm having trouble figuring out why this code isn't working. It seems like there might be a conflict between the testRed and testGreen functions. If that's the case, could someone please suggest a better approach to solving this issue? Code: ...

Using JavaScript to implement word filtering in MongoDB

I'm currently in the process of creating a chatbot designed to filter questions, and I'm seeking guidance on how to refine the search in my MongoDb based on user input. At the moment, I have the following code: I aim to retrieve all the results ...

Stopping React component click event from bubbling up to document

How do I prevent a click event in a React component from bubbling up to the document? There seems to be an issue that needs fixing! Let's see if we can resolve it on our own. I have a box component with a click event listener, and some link compone ...

What might be causing the issue in the build process of my next.js project?

**Why is my Node.js YAML file causing an error?** name: Node.js CI on: push: branches: [ "main" ] pull_request: branches: [ "main" ] jobs: build: runs-on: ubuntu-latest strategy: matrix: node-ver ...

Experiencing difficulties with loading Facebook wall feed JSON data

Struggling to integrate a Facebook wall feed using jQuery on my website's client side. Utilizing this URL for the Facebook request: Attempted approaches so far: 1. $.getJSON('http://www.facebook.com/feeds/page.php?format=json&id=407963083 ...

What causes jQuery's append function to trigger a redraw of my Div?

I have a unique function that incrementally increases the date by one day every second. Once the date matches specific dates, I aim to update my #newsDiv with extra text content. The #newsDiv will display all historical "news" and will be set to scroll to ...

How to change a POST request to a PUT request using Express and keeping the

In my express app, I have set up two routes like this: router.post('/:date', (req, res) => { // if date exists, redirect to PUT // else add to database }) router.put('/:date', (req, res) => { // update date }) W ...

The templateUrl directive with dynamic content

In order to showcase multiple popins using Angular on my homepage, I implemented the following: template1.html will appear as a popin. It worked after I corrected the .html file to display properly. <a class="vsn_alert-item-link" tooltip-special="tem ...

Guide to implementing a DataTable in MVC4 UI using jQuery

Looking to set up a DataTable using jQuery similar to the one shown in this image: https://i.stack.imgur.com/DNUcd.png I'm not very comfortable with jQuery, so please be patient and avoid asking me what I've tried. I don't know how to stru ...

Issue with Bower build failing due to the presence of "art://" in the Artifactory URL

We are experiencing an issue while building a bower project on Jenkins. The build is failing with the following error message: [ERROR] bower angular#1.3.2 EINVRES Request to https://repo.mycompany.com/api/bower/bower-repo/packages/art%3A%2F%2Fangular%2F ...

Ways to modify client socket from JavaScript to PHP

Looking for a way to convert a client socket from JavaScript to PHP in order to receive data from the server socket? Check out the PHP socket Bloatless library here. This is an example of the Client Javascript code: <script> // connect to chat appl ...

Restrict the display of items in a unordered list element

Below is my code snippet that limits the number of visible list items in a ul: $wnd.$(el) .find('li:gt(9)') .hide() .end() .append( $wnd.$('<li>+More</li>').click( function(){ $wnd.$(this).nextAl ...

Passing all emitted events from Vue 3 child component to its parent - A complete guide

My Vue components are structured as follows: <TopParent> <!-- Listening for events from EventProducer here --> <Child_1> <Child_2> <Child_3> ... <Child_N> <EventProducer /> &l ...

A step-by-step guide on fetching multiple iframe contents simultaneously with Selenium in Java

Today, I am facing an interesting challenge. I need to extract the page source of a webpage that includes an iframe. Surprisingly, when using the PhantomJSDriver with the code snippet below, I am only able to retrieve either the page content or the iframe ...

Tips for assigning unique names to each radio input groupNeed to assign unique names to radio

Currently, I am seeking a dynamic solution to alter the name associated with a set of radio input buttons. The situation involves creating a travel itinerary where users can choose between "domestic" and "international." Based on this selection, the corre ...

Navigating forwards in Angular 7 causes loss of state

I have a situation with my angular 7 Ionic application. When I navigate to a page, I use the following code snippet: navigateToDetail(entity: User) { const navigationExtras: NavigationExtras = { state: { entity, entityId: entity.id ...

What could be the source of the "Uncaught Error: write after end" error occurring in my test cases?

Below is the code I am working with: var Promise = require('bluebird'); Promise.longStackTraces(); var path = require('path'); var fs = Promise.promisifyAll(require('fs-extra')); var clone = require('nodegit').Clone ...

jQuery is successfully manipulating pagination on CodeIgniter, however, the link is being updated as well

I've been working on a HTML page called view_closing.php. It includes a table with pagination, and my aim is to ensure that the table can move to another record without refreshing the entire page, all while remaining at the same address: http://localh ...

Client.db is undefined error encountered in MongoDB backend API

I'm having trouble retrieving data from a collection in my MongoDB backend. Every time I try, I encounter an error stating that the client is not defined. Has anyone else experienced this issue and knows how to resolve it? Error: Client is not define ...