Save is not a function

I am working on an app that has a Save button. When I hit Save the first time, it works, and saves properly.

The second time it’s enabled by a change to the form, I get the following error:

save is not a function
    at getFunction (aurelia-binding.js?5f98:1998)
    at CallScope.evaluate (aurelia-binding.js?5f98:1515)
    at Call.callSource (aurelia-binding.js?5f98:5089)
    at HTMLButtonElement.eval (aurelia-binding.js?5f98:5113)

When I created a gist, it works fine. So this confuses me.

Here’s my form declaration and Save button html code:

                        <form role="form" name="form" id="dbtrform" 
                            element.ref="dbtrform" submit.delegate="save()">
                            <button type="button" class="btn" id="saveDbtr"
                                onclick.call="save()" disabled.call="canSave()">
                                Save
                            </button>

I had been using <button type="submit">, but the error was flashing by too quickly for me to read it. When I changed to a button type of button with an onclick reference, I can see the error.

Here’s my js code:

    save()
    {
      this.saveRows();
      
      this.save = 1;

      this.dbtr = this.getCustomerData(this.dbtr.debtor_id);
      
      this.gridOptions.api.refreshCells();
      this.hasChanged();

      this.save = 0;
      // I tried adding this to see if I just needed to reload the page to get things working again, 
      // but it didn't work either.
      this.setReload();

    }

canSave()
  {
    return this.hasChanged();
  }

hasChanged()
  {
    var d = document.form;
    
    debugger;

    if (this.save === 1)
    {
      d.saveDbtr.disabled = true;
      return false;
    }

    if ( typeof(d) != undefined && d != null )
    {
      d.saveDbtr.disabled = false;

      return true;
    }
    
    
    return false;
  }

I am not sure what I’m missing.

In the save method you’re changing save from a method to a value of 1/0 so the second click it’s indeed no longer a method.

Holy Cow. of COURSE.

Thanks so much for pointing this out.