question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

swal.disableConfirmButton() not working

See original GitHub issue

I just noticed this does not work and throws a "ERROR TypeError: sweetalert2_1.default.disableConfirmButton is not a function"

To reproduce just create a new project with Angular CLI (I’m using version 1.6.6) and modify app.component.ts a bit:

import { Component } from '@angular/core';
import swal from 'sweetalert2';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'app';

  constructor() {
    swal.disableConfirmButton();// <-- this doesn't work
    swal("sfsdfdsfd");// <-- this works fine
  }
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
toveruxcommented, Jan 30, 2018

Yes, those DOM-related functions are created after the first modal is shown. They do not set a state on which the button state is based: these are imperative DOM manipulations.

That’s why I use thunks here (see comment): https://github.com/sweetalert2/ngx-sweetalert2/blob/master/src/swal-partial-targets.ts#L3 (by the way, you just gave me a wonderful feature idea, thanks 😄).

You first need to request a modal in order to use disableConfirmButton(). You can use the onOpen hook to perform your call (onOpen is called before the modal is shown, but when its DOM is already created, therefore you won’t see the button “blink”):

swal({
  onOpen: () => swal.disableConfirmButton()
});

JSFiddle demo.

1reaction
zenflowcommented, Mar 1, 2018

I think this can be closed? Maybe one day we’ll have some kind of modal instances and not just utility function to manipulate the modals’ DOM, but this is another story.

@toverux @limonte It is possible to change the new context object to a class instance and move code into instance methods. In fact the only reason I didn’t do this in #969 was to avoid the huge code change that’s hard to review and can result in merge conflicts.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Disable Confirm Button conditionally in sweetalert
PS: In documentation I found swal.disableConfirmButton() method but while using the same Angular throws an error
Read more >
Change button state using sweetalert2 : r/learnjavascript
I tried that approach but it is not working. ... showLoading() }) // in whatever function your element calls after loading Swal.
Read more >
disable confirm button swal - Code Examples & Solutions For ...
disable button in swal popup ; 1. function DeleteConfirm(c){ ; 2. swal({ ; 3. title: "Want to delete this item?", ; 4. text:...
Read more >
SweetAlert2 - Translider Demenagement
Disable the "Confirm"-button only. swal.showLoading() or swal.enableLoading(), Disable buttons and show loader. This is useful with AJAX requests. swal.
Read more >
SweetAlert2 - MIT Muzaffarpur
}).then(function () { swal( 'Deleted!', 'Your file has been deleted. ... showConfirmButton, true, If set to false, a "Confirm"-button will not be shown....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found