Home  /  Questions  /  Question



50   50
Apr 15, 2017


Patterns in Action - JavaScript DataEntry app

I think I found a bug in the code. On the Update Customer function you are adding a customer instead of updating.

                    // this is wrong
                    //databaseCustomers.push(context.data);

Also, on the Submit function, what is the purpose of the line wherte var mod is set to the this.collection.get....

submit: function (event) {
                event.preventDefault();
               
                if (this.model.isNew()) {     // add
                    this.collection.create({
                        first: this.$('#first').val(),
                        last: this.$('#last').val()
                    });

                } else {       // update

                    var mod = this.collection.get(this.model.get("id")); <<<<===== what is this doing? mod is not used anywhere?
                  
                    this.model.set("first", this.$('#first').val());
                    this.model.set("last", this.$('#last').val());
                    var url = this.model.url;
                  
                    this.model.url = "customers";
                    this.model.save();
                    this.model.url = url;
                }
                this.$el.empty();
            },
            cancel: function (event) {
                event.preventDefault();
                this.$el.empty();
            }
        });