Ways to stop users from submitting a form repeatedly in Angular

In my current feature, users have the ability to create new data and save it. If the data already exists, a modal will pop up as shown in the image below:

However, there is an issue when the user clicks the save button multiple times while the request is still pending. This triggers the "Data already exists wanna proceed on saving?" popup to appear again, which is not desired.

As depicted in the screenshot below, if the request is still pending and the user clicks the button again, the popup will appear once more. How can we resolve this using Angular? Any helpful ideas or suggestions would be greatly appreciated. Thank you.

Save data snippet

listenToSaveEvent(): void {
    this.saveSubject
      .asObservable()
      .pipe(
        filter((v) => !!v),
        debounceTime(1e3)
      )
      .subscribe(() => {

        if (this.respondents.length === 1) {
          return this.checkExistingData();

CODE THAT CHECKS EXISTING DATA

checkExistingData(): void {
    const test = this.formService.checkExisting(this.form)
    .subscribe(res => {
      if (res ) {
        const createExistingSub = this.confirmDialogService.open(
          ERROR_MESSAGES."Data already exists wanna proceed on saving?"
        )
          .componentInstance
          .confirmed
          .subscribe((confirmed) => {
            if (confirmed) {
              return this.createDATA();
            }

            createExistingSub.unsubscribe();
      });
      } else {
          return this.createDATA();
      }
  });

Answer №1

To enhance the user experience, consider disabling the button during processing and adding a loader animation. This will effectively communicate to the user that the request is still being processed, mitigating any potential issues that may arise.

Answer №2

Implement a toggle to switch between pre and post upload actions

`listenToSaveEvent(): void {
    if (this.isUploading) { return;}  // do nothing while uploading
    this.isUploading = true;
    this.saveSubject
      .asObservable()
      .pipe(
        filter((v) => !!v),
        debounceTime(1e3),
        finally(() => this.isUploading === false)   // no matter if it's success or error
      )
      .subscribe(() => {
 
        if (this.respondents.length === 1) {
          return this.checkExistingData();`

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

Ensuring Proper Angular Deployment of Assets Path

Develop the project using Angular7. Once built using the command ng-build --prod --base-href /client/product/v2/ Deploy it in a vs folder, following this structure: www.domain.com/client/product/vs All images are located in the assets folder, which i ...

Managing multiple subscriptions in Angular observables

Upon initializing my component, the ComProductService is responsible for retrieving and processing the third level of product categories and storing them in proCatThird within the service. However, when attempting to access the proCatThird value in my fill ...

Is there a way to change the font size with a click in JavaScript or Angular?

Here is a breakdown of the 4 steps: 1.) Begin by clicking on a category 2.) The filtered products will be displayed 3.) Select the desired products from the filter 4.) Once selected, the products will appear in the rightmost part of the screen within t ...

Having trouble with installing Bootstrap in Angular 5

My journey with Bootstrap began by executing the command below: npm install --save bootstrap The installation was a success, and I proceeded to incorporate the CSS as follows: "styles": [ "../node_modules/bootstrap/dist/css/bootstrap.min.css", ...

Develop dynamic components in Angular using up-to-date methods

I currently have three components named PersonComponent, AddressComponent, and CompanyComponent all already defined. Is there a way to dynamically create each component when I have the component name as text, for example, "PersonComponent"? I have inject ...

What is the best time to initialize .env variables in a NodeJS application?

Building a NodeJS Express REST API with TypeScript requires loading environment variables using the dotenv package. In my code, I access the .env variables in two different files: index.ts, which serves as the entry point, and in a separate file called My ...

Determining the length of an array of objects nested within another object

I received a response from the API called res. The response is in the following format: {"plan":[{"name":"ABC"},{"name":"DEF"}]}. I am attempting to save this response in my TypeScript code as shown below: ...

Display all locations within the boundaries of the maps in Angular using Google Maps

I have integrated the following Framework into my Angular 6 project: https://github.com/SebastianM/angular-google-maps This is my first Angular project, so I am still navigating my way through it. The current status of my project is as follows: I have s ...

When attempting to initiate a new Angular project, the error below is being encountered

Seeking assistance with this error. I am attempting to create a new angular app using ng new app-name, but encountering the following issue. Being new to Angular, I'm unsure about the cause of this error. CREATE angular-app/e2e/src/app.e2e-spec.ts (3 ...

Error in Angular 8: The type of '[object Object]' is an object, whereas NgFor only supports binding to Iterables such as Arrays

I recently started using Angular 8 and I'm dealing with an issue while trying to fetch data from an http get request. I am attempting to iterate through the data using *ngFor but unfortunately encountering this error. Any suggestions on how to resolv ...

Angular 5 - Empty array containing objects has a length of zero

In my app.component.ts file, I have an array initialized to load objects in the onInit event: ngOnInit() { this.pages = []; } Within the ngOnInit event, I also have a setInterval method that evaluates an expression every few milliseconds: setInterval(() ...

Angular Jasmine Test: Anticipated the invoked spy to have been executed

Examining a confirmation dialog in Angular 8 has led to an interesting discovery: one test passes while others fail, even though they are quite similar. The tests being conducted are for three statuses: Approve, Reject, and Reset. Interestingly, the test f ...

Error in ReactJS VSCode while integrating Cypress testing: The name 'cy' cannot be found

Currently working on a ReactJS Typescript project using NPM and VSCode. Despite all my Cypress tests running smoothly, I am encountering a syntax error in VSCode: Error: Cannot find name 'cy' Any ideas on how to resolve this issue? https://i.ss ...

Why does the private map function in the class fail while the global function succeeds?

Issues arise when calling the map() function on a parsed JSON object within the mapStocks() function. Placing the toStock() function inside the StockService class results in failure, whereas declaring it as a "global" function outside the class works witho ...

Navigating to a Child Module within a Parent Module in Angular 2 Release Candidate 5

I am currently in the process of updating an application I have been working on to the latest Angular 2 release candidate. As part of this upgrade, I am utilizing the NgModule spec and transitioning all parts of my application into modules. So far, the tra ...

Determine the index of a specific character within a string using a "for of" loop

How can I obtain the position of a character in a string when it has been separated programmatically using a for...of loop? For instance, if I wish to display the position of each character in a string with the following loop: for (let c of myString) { ...

How can we reduce the size of a JSON object in Typescript before sending it to the client?

Currently, I am faced with a common challenge. I have a database object that is a standard JS object originating from a document database, and my goal is to transmit this object to the client. However, certain fields contain sensitive information that shou ...

Encountering "Module ts-jest not found in the transform option" Error During Bazel Testing

In my working Bazel BUILD file, I have set up the following configurations: package(default_visibility = ["//visibility:public"]) load("@io_bazel_rules_docker//nodejs:image.bzl", "nodejs_image") load("@npm_bazel_typescript//:index.bzl", "ts_library") # ...

The correct way to incorporate a global property into a component template (using Vue 3, Vite, TypeScript, and the Composition API)

The component's property is not functioning properly https://i.sstatic.net/qaUG9.png src/main.ts import { createApp } from 'vue' import languagePlugin from '@/plugins/languagePlugin' import App from './App.vue' const a ...

Ngrx 8: Strategies for mocking various selectors with distinct return values

I am currently in the process of writing unit tests for an Angular 8 component that has a dependency on an ngrx store. I have multiple selectors set up within the ngOnInit function and I am looking to mock these selectors using the overrideSelector method. ...