Angular setPristine function is not functioning properly

I am looking to achieve a simple task - cleaning the $scope.user fields without encountering errors.

if ($scope.contactForm.$valid) {
    $scope.user = {};
    $scope.contactForm.$setPristine();                   
}

However, I'm still experiencing validation errors such as 'required', and even when there are no errors, all of them are displayed.

You can check out the Plunker example here.

Answer №1

Here is a suggestion to resolve your issue:

 $scope.submissionStatus = true;
 if ($scope.formValidation.$valid) {
   $scope.submissionStatus = false;
   $scope.userInfo = {};
   $scope.formValidation.$setPristine();                   
 }

In your initial code snippet, the function checkError relies on the submitted flag. If the form passes validation, you can reset the submitted flag to hide any errors.

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

Switching Languages in react-simple-keyboard: Explained

import React, { useRef, useState } from "react"; import Keyboard from "react-simple-keyboard"; import "react-simple-keyboard/build/css/index.css"; function App() { const [input, setInput] = useState(""); const [ ...

Add a JavaScript library to the header directly from the body of a webpage, ensuring it is exclusive to a single

I am using the Google Charts JS library on a single page within my project, with external and global headers and footers. The head tags are located in a head.php file, where all required JS libraries are included. The structure of my pages is as follows: ...

Conversion tracking for Facebook Pixel is not being updated properly within the Ionic framework

Have a question about tracking with FB pixel for FB Ads? I want to track user registration in my app, so I placed the tracking code between the <head></head> tags in index.html. I commented out the <img> tag and added fbq('track&ap ...

"Can you tell me a way to identify variances between two dates displayed in a

I am looking to calculate the differences between two dates. I will input the date values in the text box and want the duration to be displayed in another text box. <script language=javascript> function formshowhide(id) { if (id == ...

What is the best location to place an HTML wrapper element within a React Project?

Just diving into the world of React, I've embarked on a simple project with bootstrap My goal is to reuse a specific HTML structure: <div className="container"> <div className="row"> <div className="col-lg-8 col-md-10 mx-auto"&g ...

Flatbuffers does not exist in this context

Currently, I am working on a nodeJs application that involves the use of Google Flat Buffer. After installing flatc on my MacBook Pro, I compiled the schema below: namespace MyAlcoholist; table Drink { drink_type_name: string; drink_company_name: stri ...

Unable to include any additional Angular Module

While using Jhipster v3.9.1, I attempted to add a module to my project but encountered some difficulties. Specifically, I wanted to incorporate the module found at . To achieve this, I ran the command bower install angular-mass-autocomplete --save followed ...

What is the best way to delete a nested document within an array in MongoDB by referencing its _id?

I am trying to remove a nested object from an array of objects called createdEvents if the createdEventId matches the id I pass to it. This is the JavaScript query I am using: db.collection("users").updateOne({ _id: userId }, { $pull: { createdEv ...

Is it possible to track the movement of two phones within a specific location?

I'm currently working on a mobile app using Ionic that requires the backend or another user to be able to detect the movement of a different user. Here's how it would work: I need to mark a location with specific coordinates and save them. Onc ...

Switch to a different form when clicked using JavaScript

Can you assist me with my code issue? The scenario is as follows: I have two forms - one for registration and one for login. I want to dynamically replace the login form with the register form when the user clicks on the "Sign up" link. Similarly, if the ...

CloudFront for Amazon - Limit MP3 playback to designated website

I've been trying to find a solution for allowing mp3 files in an Amazon S3 bucket paired with Cloudfront to be streamed directly on my site without revealing the source URL of the mp3s. I want to prevent others from sharing or leeching the link by vie ...

Value in ng-model does not display in the <select> element

My HTML code looks like this: <label class="item item-input item-stacked-label" ng-repeat="nl in normativas"> <select ng-model="nl.idResultado"> <option value="1">OK</option> <option value="2">NOT</op ...

Customizing the "added to cart" message in Woocommerce and setting up a notification system for customers

My main focus is on customizing the Woocommerce notation system for a personalized shopping cart experience. After some research, I stumbled upon a very helpful user response which suggested modifying the message by adding the following code snippet to th ...

How come my data cannot be displayed using ajax?

Here is the code snippet: var xml=new String(""); //function to send data every 5 seconds window.setInterval(function() { //code to obtain xml file alert(xml);// when I try alert my variable xml contain data ...

Retrieve information from the pouchdb database

After successfully storing data in PouchDB, I'm wondering how to retrieve this information and display it in HTML using AngularJS. var db = new PouchDB('infoDB'); function getData(){ $.getJSON('test.json', function(data) { ...

The primeVue menubar's active/focused item highlighting feature is not functioning correctly

Currently, we are in the process of developing an electron-based application with the front end primarily coded using Vue.js and primeVue. As a novice, I am encountering issues with the menubar component from primeVue. The problem is that no matter which i ...

Tips for guaranteeing blocking within a loop in Node.JS

While I usually enjoy the asynchronous nature of Node.JS and its callback-soup, I recently encountered an issue with SQLite that required a certain part of my code to be run in a blocking manner. Despite knowing that addressing the SQLite problem would mak ...

What are some ways I can improve the readability of this if-else function in Javascript ES6?

As a newcomer to React development, I am currently in the process of tidying up my code. One issue that I am facing is how to deal with a particular function while minimizing the use of if-else statements. const calculatePerPage = () => { if ...

Leveraging the Firebase email trigger extension with JavaScript

Recently, I integrated the email trigger extension for Firebase. Below is the function I am using: firestore .collection("profiledata") .doc(user.uid) .update({ accountStatus: "active", }) .then(() => { // At this p ...

AngularJS - Regular Expression Error

I have implemented a RegEx pattern to validate passwords entered by users. The password must contain at least 1 capital letter, 1 number, and 1 symbol: /(?=.*?\d)(?=.*?[a-z])(?=.*?[A-Z])(?=.*?[^a-zA-Z\d])/ When this RegEx is used with ng-patter ...