Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8625713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:51:24+00:00 2026-06-12T07:51:24+00:00

I am able to post my forms to my database and I have stepped

  • 0

I am able to post my forms to my database and I have stepped through my back end function to check and see that my Get function is returning the same data I submitted. However I am having trouble understanding how to have this data rendered upon visiting the page again. What am I missing? The intention is to be able to create, read, update, or delete (CRUD) some personal contact data for a variable collection of individuals.

//Model
var PersonItem = Backbone.Model.extend({
    url: "/Application/PersonList",
    idAttribute: "PersonId",
    schema: {
        Title: {
            type: 'Select',
            options: function (callback) {
                $.getJSON("/Application/GetTitles/").done(callback);
            }
        },
        Salutation: { type: 'Select', options: ['Mr.', 'Mrs.', 'Ms.', 'Dr.'] }, 
        FirstName: 'Text',
        LastName: 'Text',
        MiddleName: 'Text',
        NameSuffix: 'Text',
        StreetAddress: 'Text',
        City: 'Text',
        State: {
            type: 'Select',
            options: function (callback) {
                $.getJSON("/Application/GetStates/").done(callback);
            }
        },
        ZipCode: 'Text',
        PhoneNumber: 'Text',
        DateOfBirth: 'Date',
    }
});
Backbone.Form.setTemplates(template, PersonItem);
//Collection
var PersonList = Backbone.Collection.extend({
    model: PersonItem
    , url: "/Application/PersonList"
});
//Views
var PersonItemView = Backbone.Form.extend({
    tagName: "li",
    events: {
        'click button.delete': 'remove',
        'change input': 'change'
    },
    initialize: function (options) {
        console.log("ItemView init");
        PersonItemView.__super__.initialize.call(this, options);
        _.bindAll(this, 'render', 'remove');
        console.log("ItemView set attr = " + options);
    },
    render: function () {
        PersonItemView.__super__.render.call(this);
        $('fieldset', this.el).append("<button class=\"delete\" style=\"float: right;\">Delete</button>");
        return this;
    },
    change: function (event) {
        var target = event.target;
        console.log('changing ' + target.id + ' from: ' + target.defaultValue + ' to: ' + target.value);
    },
    remove: function () {
        console.log("delete button pressed");
        this.model.destroy({ success: function () { alert('person deleted successfully'); } });
        return false;
    }
});

var PersonListView = Backbone.View.extend({
    el: $("#application_fieldset"),

    events:
        {
            'click button#add': 'addPerson',
            'click button#save': 'save2db'
        },
    initialize: function () {
        console.log("PersonListView Constructor");
        _.bindAll(this, 'render', 'addPerson', 'appendItem', 'save');
        this.collection = new PersonList();
        this.collection.bind('add', this.appendItem);
        //this.collection.fetch();
        this.collection.add([new PersonItem()]);
        console.log("collection length = " + this.collection.length);
    },
    render: function () {
        var self = this;
        console.log(this.collection.models);
        $(this.el).append("<button id='add'>Add Person</button>");
        $(this.el).append("<button id='save'>Save</button>");
        $(this.el).append("<fieldset><legend>Contact</legend><ul id=\"anchor_list\"></ul>");
        _(this.collection.models).each(function (item) {
            self.appendItem(item);
        }, this);
        $(this.el).append("</fieldset>");
    },
    addPerson: function () {
        console.log("addPerson clicked");
        var item = new PersonItem();
        this.collection.add(item);
    },
    appendItem: function (item) {
        var itemView = new PersonItemView({ model: item });
        $('#anchor_list', this.el).append(itemView.render().el);
    },
    save2db: function () {
        var self = this;
        console.log("PersonListView save");
        _(this.collection.models).each(function (item) {
            console.log("item = " + item.toJSON());
            var cid = item.cid;
            console.log("item.set");
            item.set({
                Title: $('#' + cid + '_Title').val(),
                Salutation: $('#' + cid + '_Salutation').val(),
                FirstName: $('#' + cid + '_FirstName').val(),
                LastName: $('#' + cid + '_LastName').val(),
                MiddleName: $('#' + cid + '_MiddleName').val(),
                NameSuffix: $('#' + cid + '_NameSuffix').val(),
                StreetAddress: $('#' + cid + '_StreetAddress').val(),
                City: $('#' + cid + '_City').val(),
                State: $('#' + cid + '_State').val(),
                ZipCode: $('#' + cid + '_ZipCode').val(),
                PhoneNumber: $('#' + cid + '_PhoneNumber').val(),
                DateOfBirth: $('#' + cid + '_DateOfBirth').find('input').val()
            });

            if (item.isNew()) {
                console.log("item.isNew");
                self.collection.create(item);
            } else {
                console.log("!item.isNew");
                item.save();
            }
        });
        return false;
    }
});
var personList = new PersonList();
var view = new PersonListView({ collection: personList });
personList.fetch({ success: function () {
    $("#application_fieldset").append(view.render());
}
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:51:25+00:00Added an answer on June 12, 2026 at 7:51 am

    I figured out my bug. I needed to remove the creating of a new PersonList inside my PersonListView initialize.

          this.collection = new PersonList();//removed this line
    

    Hopefully this code helps someone with backbone forms. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The get works fine and able to post to the database with a test
I can able to post the tweet through my application using C# with twitterizer
I have a web page where people are able to post a single number
I have map.resources :posts and I want to be able to serve post bodies
I have a scraping object basically. I want to be able to add POST
I have a form that I am using to post data to mysql. Before
I have a little Mac application which should be able to post Data to
I have a file upload function in my asp.net mvc application that allows users
I have a site in development with several web services (ASMX) that post important
I have an issue where I need to be able to use check boxes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.