Modals should have option to prevent modal close on conditions.

EDIT: Just figure it out by passing the promise to a variable. I guess I should have known better 🙂

It would be nice if we could prevent the modal from closing based on conditions.

Making use of the example in the web site:

 open(content) {
    this.modalService.open(content).result.then((result) => {
      this.closeResult = `Closed with: ${result}`;
    }, (reason) => {
      this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
    });
  }

There is no way of doing something like if (true) { modal.preventClose() } or similar. I still want to allow users to close the modal on dismiss. The only restriction should be some values that are set on inputs.
I tried finding a way of using something similar with a preventDefault without success. I ended up implementing a slight hack that works for my purposes which is to recursively opening the modal again, like so:

openEditModal() {
    this.NgbModal.open(this.editNodeModal).result.then(() => {
        if (max.value > minValue) {
                this.openEditModal();
                this.validationErrorWarning = true;
            }
    }
}

1 possible answer(s) on “Modals should have option to prevent modal close on conditions.