lundi 30 octobre 2017

Prevent showing error when multiple clicking on link tag

My question is: how to prevent application from throwing

Call to a member function destroy() on null

on user's browser when fast/double clicking on a link HTML element on a laravel project:

<a href="{!! route('models.destroy', $model->id) !!}" class="btn btn-danger>Confirm</a>

For a similar problem with form submit buttons I used kjdion84's answer:

$('form').submit(function (event) {
    if ($(this).hasClass('submitted')) {
        event.preventDefault();
    } else {
        $(this).find(':submit').html('<i class="fa fa-spinner fa-spin"></i>');
        $(this).addClass('submitted');
    }
});

But the adaptation I tried didn't work out, either with class or id selectors:

$('a .btn-danger').click(function (event) {
    if ($(this).hasClass('pressed')) {
        event.preventDefault();
    } else {
        $(this).addClass('pressed');
    }
});

I also tried this simpler answer, but event.preventDefault() doesn't seems to work and using dblclick doesn't make a difference.

I'm open to other than Javascript ways of solving this.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire