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 7612659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:58:11+00:00 2026-05-31T01:58:11+00:00

Is there a way to suppress model validation in Backbone.js when a new model

  • 0

Is there a way to suppress model validation in Backbone.js when a new model is first created?

In my app, I have a collection with an arbitrary number of models, which are represented as list items. The user can click a button on each item, which inserts a new empty item beneath the current item. The empty item is failing validation, obviously, because I don’t want an empty item being saved later.

There’s no way for me to know what sensible defaults might be when I’m creating the new item, so prepopulating the new model with valid data doesn’t seem like an option.

Any suggestions?

Update: While working on a tangentially related problem, I realized that I was using Backbone.js version 0.9.0. When this version was released, other people had the same problem I was having, and they complained in this issue on GitHub.

Jeremy modified validation in 0.9.1 to fix this. Adding a (temporarily) empty model to a collection is a valid real-world usecase. You could handle the new, empty model in the view, but if you’re managing a list of items like I am, that forces you to have a collection of item views (including the empty one) in addition to your collection of must-be-valid models. That’s a really clunky workaround for an otherwise straightforward scenario. Glad this got fixed.

  • 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-05-31T01:58:13+00:00Added an answer on May 31, 2026 at 1:58 am

    You’re not supposed to add invalid models 🙂

    Digging a bit in Backbone source code (0.9.1 at least) showed that the mechanism can be circumvented by passing options to your add method:

    var Mod=Backbone.Model.extend({
        validate: function(attrs,opts) {
            if (opts.init) return;
            return "invalid";
        }
    });
    
    var Col=Backbone.Collection.extend({
        model:Mod
    });
    
    var c=new Col();
    c.add({},{init:true});
    
    console.log(c.length);
    

    A Fiddle: http://jsfiddle.net/jZeYB/

    Warning : it may break things down the line.

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

Sidebar

Related Questions

Is there any way to suppress the pop-up titles on links, yet still keep
Is there a way to suppress warnings in C# similar to Java's @SuppressWarnings annotation?
Is there any way to suppress Compiler warnings ?? Thanks
Is there any way to suppress the default js and css loaded by application.html.erb
Is there way in next piece of code to only get the first record?
I have a simple model setup in my Ruby on Rails app. (User {name,
Is there a way to suppress the output from popen() without losing the Wait().
Is there a way to suppress the following warning? warning rsOverlappingReportItems: The image 'image3'
Is there a way to suppress x rows affected in SQLCMD from the command
Is there any way to suppress or kill all activities and non crucial applications

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.