Reputation: 33
I have this code in JS. The purpose of this is that, when the #savecard-button
is clicked, it will go through submitting, but will delay it for a certain amount of time and then go through the process and so on.
$('#savecard-button').on('click', function(){
$('#savecard-button').submit('loading').delay(1000).queue(function () {
if ($('#form-addcard').find('.has-error').length) {
return false;
}else{
$(this).attr('disabled',true);
$(this).html('<i class=".$code."></i> Saving Changes');
$(this).button('reset');
}
});
});
but when trying to submit, I get this error on the console:
Uncaught TypeError: Cannot create property 'guid' on string 'loading'
Is the parameter "loading" depreciated? Because months ago, its still working. If so, can you please advise what I have to replace here? Thanks
Upvotes: 1
Views: 6775
Reputation: 33
I was able to get my button's loading state work properly after a few experiments on the code. I got rid of the "loading" parameter as I think the submit function doesn't have it.
$('#savecard-button').on('click', function() {
var $this = $(this);
//$this.attr('disabled',true);
$this.html('<i class="fa fa-spinner fa-spin"></i> Saving Changes');
setTimeout(function() {
$this.attr('disabled',true);
$this.button('reset');
}, 0);
});
Upvotes: 1
Reputation: 2176
There's at least two problems:
$('#form-addcard').submit()
submit
function you will see that it requires a function as a parameter. Right now you're passing it a string. You don't mention what you're trying to do by passing 'loading' to the submit
function. If it's genuinely a function you want to execute when the submit event is triggered, then make sure a "loading" function actually exists somewhere.Upvotes: 1