jaegyo23
jaegyo23

Reputation: 33

Cannot create property 'guid' on string 'loading'

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

Answers (2)

jaegyo23
jaegyo23

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

sg-
sg-

Reputation: 2176

There's at least two problems:

  1. I assume "#savecard-button" is a button (ie: input type="button")? If so, right now you're trying to submit a button. That won't work. You can only submit forms. Possibly you want $('#form-addcard').submit()
  2. If you check the JQuery documentation for the 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

Related Questions