Tengo un método que verifica si alguna propiedad del objeto en la matriz es igual a 'no listo'. Si es así, debe informar al usuario sobre eso y preguntarle si aún desea continuar. Si no, hay un retorno que rompe el método y si es así, el método continúa y hay un cuadro de diálogo de confirmación más
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* } });Así se ve en 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>Mi problema es que ambos diálogos de confirmación aparecen al mismo tiempo. Supongo que es por usar dos veces en html. Pero si cambio eso a
<p-confirmDialog></p-confirmDialog>Solo funciona el primero ('Ya está en curso...') y el segundo ('¿Estás seguro') después de hacer clic en Sí no aparece. ¿Cómo hago para que funcione?
Debería estar llamando al segundo cuadro de diálogo después de que ocurra la confirmación. Lo que sucede al accept o reject devoluciones de llamada. Pero está llamando inmediatamente a this.confirmationService.confirm nuevamente y está causando que se muestren ambos cuadros de diálogo.
Deberías tener algo como lo siguiente:
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* } }); }