0

1.I want form should gives bootbox confirm popup and after clicking on confirm button of bootbox should submit the form**[Important]**

2.Bootbox Popup is coming on clicking update button but it should not submit the form on clicking confirm button of bootbox.(in alert it gives true value on clicking confirm)

javascript:  
$('.linkmasterdata').submit(function(e)
{
    bootbox.confirm({
        title: "Confirmation Message?",
        message: "Do you want to update this form?.",
        buttons: {
            cancel: {
                label: '<i class="fa fa-times"></i> Cancel'
            },
            confirm: {
                label: '<i class="fa fa-check "></i> Confirm'
            }
        },
        callback: function (result) {
            console.log('This was logged in the callback: ' + result);
            if (result == true) {
              $("#submit").click();     
            }
        }
    });
    e.preventDefault();
});     

{!! Form::model($law, array('route'=>array('admin.forms.update', 
  $forms->id),'id'=>'linkmasterdata', 'class' => 'form-horizontal edit_form', 
         'method' => 'PUT', 'files' => true)) !!}

<input type="submit" id="submit" class="btn btn-success submit" value="Update">

{!! Form::close !!}
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 2
    If I'm parsing your code correctly, it looks like you're going to be stuck in a bit of a loop, here. You're using the Bootbox confirm in the submit event handler for your form, but then triggering a click of the submit button of your form if the user clicks OK. That would re-trigger the submit event and you're right back where you started. – Tieson T. Nov 10 '17 at 08:06
  • 1
    just return true​ in the callback rather that triggering submit again – Muhammad Omer Aslam Nov 10 '17 at 08:33
  • @MuhammadOmerAslam on return true its only close bootbox ,I want to submit the form on Confirm click – Nikhil Nov 10 '17 at 08:45
  • can you add a code snippet – Muhammad Omer Aslam Nov 10 '17 at 08:49
  • @TiesonT. yes its re-triggering ...then what is the solution for this . – Nikhil Nov 10 '17 at 09:15
  • There isn't really a clean way of handling a re-trigger. The simplest method I've found is to have a Boolean variable that I use to track if I've handled the submit event already. Something like `var canSubmit = false;` before the event handler, and then wrap the `bootbox.confirm(...)` code in a conditional, setting canSubmit to true in the callback before triggering the submit again. I think I've posted something like that in a previous answer to a similar question. – Tieson T. Nov 12 '17 at 04:11
  • You may also want to read this question: https://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-asynchronous-call - using Promises is probably the best solution. – Tieson T. Nov 12 '17 at 04:15

0 Answers0