Dofactory.com
Dofactory.com
 Back to list
Views:   2.5K
Replies:  0
Archived

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();
            }
        });


Everardo Cunha, Apr 15, 2017
Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Cookies       Do Not Sell       Licensing      
Made with    in Austin, Texas.  - vsn 44.0.0
© Data & Object Factory, LLC.