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.

inconsistent behaviour: form not always being saved

See original GitHub issue

Whenever I submit a form it is not being saved consistently when using sweet alert. Between 2 and 5 submits the form suddenly fails to save. Have tried in many ways but all seem to suffer from the same issue (some examples provided below). For example, I submit the form and it can saved, the first time, the second time, and the third time suddenly the forms are not being saved.

<script>
    $('#btn-sw-confirmation').on('click', function() {
        swal({
            title: "Confirm?",
            text: "Are you sure?",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: '#41B314',
	    cancelButtonColor: '#F9354C',
            confirmButtonText: "Confirm",
            cancelButtonText: "Back"
          }
        ).then(
          function (isConfirm) {
            if (isConfirm) {
              console.log('CONFIRMED');
              swal('Saved!', 'Your file has been saved.', 'success');
            }
          },
          function() {
            console.log('BACK');
          });
        return false;
    });
  </script>

or

<script>
    $('#btn-sw-confirmation').on('click', function() {
        swal({
            title: "Confirm?",
            text: "Are you sure?",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "Confirm",
            cancelButtonText: "Back",
            showLoaderOnConfirm: true,
          }
        ).then((isConfirm) => {
            if (isConfirm) {
              console.log('CONFIRMED');
              swal('Saved!', 'Incident reported.', 'success');
            }
          },
          function() {
            console.log('BACK');
          });
        return false;
    });
  </script>

or

  <script>
    $('#btn-sw-confirmation').on('click', function (e) {
      e.preventDefault();
        swal(
          {
            title: 'Are you sure?',
            text: "You won't be able to revert this!",
            type: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#41B314',
            cancelButtonColor: '#F9354C',
            confirmButtonText: 'Yes, save it!'
          }
        ).then(swal(
                'Saved!',
                'Incident reported.',
                'success'
              )
        ).catch(swal.noop);
     });
  </script>

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
gvernicommented, Apr 28, 2019

@sitWolf it’s pretty clear from the video that the SweetAlert2 gets executed correctly both times (i.e. the two alerts are shown in both occasions). So why do you think the issue is with SweetAlert? Have you checked the browser console to debug the issue?

2reactions
gvernicommented, Apr 28, 2019

Hi @sitWolf which version of SweetAlert are you using? Clearly you are not using the latest version since the swal is now invocated using Swal.fire().

I tried your code (with some changes) on the latest version and I haven’t reproduced the issue. Please provide a live example using the instructions here

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tired of inconsistency in relationships? Signs of emotional ...
Inconsistent behaviour is nothing less than a form of emotional abuse. And we often come across people who exhibit emotional inconsistency.
Read more >
Inconsistency in Relationships is a Form of Emotional Abuse
If a person is consistently inconsistent, the behavior is likely to be conscious. We're not always going to be in a good mood....
Read more >
The Time Inconsistency Problem and How It's Hurting You
Time inconsistency is how our behavior and desires change over time. ... We all know that saving money and not eating cookies can...
Read more >
Save in State inconsistent behavior · Issue #2779 · formio ...
I have a form where i am using my own onSubmit function. However, the feedback to the user is inconsistent, and I'm not...
Read more >
Inconsistent behaviour for HTML patterns - Stack Overflow
While supporting browsers will all prevent a form submission if it's invalid, everything outside of that is a browser design decision.
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