Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

254
Views
Primeng confirm dialog show when it shouldn't

I have a method that checks if any property of object in array is equal to 'not ready'. If it is it should inform user about that and ask if he still wishes to continue. If no, there is return that breaks the method and if yes, method continues and there is one more confirm dialog

createOrder() {
    if(this.orders.filter(e => e.statusName === 'not ready').length > 0){
      this.confirmationService.confirm({
        message: 'There is already ongoing order. Do you want start another?',
        header: 'Order',
        icon: 'fa fa-exclamation-triangle',
        acceptLabel: 'Yes',
        rejectLabel: 'No',
        key: 'ongoin',
        accept: () => {
        },
        reject: () => {
          return
        }
      })
    }
    
    this.confirmationService.confirm({
      message: 'Are you sure?',
      header: 'Order',
      icon: 'fa fa-exclamation-triangle',
      acceptLabel: 'Yes',
      rejectLabel: 'No',
      key: 'confirm',
      accept: () => {
       *//add object code*
      }
    });

This how it looks like in html:

<button pButton tooltipPosition="left" (click)="createOrder()" icon="fa fa-plus-square"
          class="ui-button-warning">
        </button>
        <p-confirmDialog key='ongoin'></p-confirmDialog>
        <p-confirmDialog key='confirm'></p-confirmDialog>

My problem is that both confirm dialogs shows up at the same time. I guess it is because of using twice in html. But if i change that to

<p-confirmDialog></p-confirmDialog>

Only the first one works ('There is already ongoin...') and second one('Are you sure') after clicking yes doesn't show up. How do I make it work?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You should be calling the second dialog after the confirmation happens. Which happens in accept or reject callbacks. But you are immediately calling this.confirmationService.confirm again and it is causing both dialogs to be shown.

You should be having something like below :

createOrder() {
    if(this.orders.filter(e => e.statusName === 'not ready').length > 0){
      this.confirmationService.confirm({
        message: 'There is already ongoing order. Do you want start another?',
        header: 'Order',
        icon: 'fa fa-exclamation-triangle',
        acceptLabel: 'Yes',
        rejectLabel: 'No',
        key: 'ongoin',
        accept: () => {
         // do something here
         this.showAnotherDialog();
        },
        reject: () => {
         // if you want to show another dialog on reject you should call it here
          return
        }
      })
    } else {
       this.showAnotherDialog();
   }   
}

showAnotherDialog() {
   this.confirmationService.confirm({
      message: 'Are you sure?',
      header: 'Order',
      icon: 'fa fa-exclamation-triangle',
      acceptLabel: 'Yes',
      rejectLabel: 'No',
      key: 'confirm',
      accept: () => {
       *//add object code*
      }
    });
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!