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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:12:16+00:00 2026-05-28T04:12:16+00:00

I keep running into this problem over and over. I have a view with

  • 0

I keep running into this problem over and over. I have a view with an input and I want to set and update things on every keyUp event. The problem is when set is called it triggers a change event which re-renders the view which causes the input to lose focus. So after the user types one character the input loses focus and they can’t type anymore.

Another case where this happens is when the user clicks on an input I want to add a class to the div around the input so that it changes color. This of course causes the view to re-render and the input loses focus. I can’t simply make a separate view for the input because the input is inside the div I want to re-render.

Here’s a simple example.

itemView = Backbone.View.extend({
events: {
    "keyup .itemInput": "inputKeyUp"
}
initialize: function(){
    this.model.view = this;
    this.bind('change', this.render());
    this.render();
},
render: function(){
    $(this.el).html( $(ich.itemView( this.model.toJSON() )) );
    return this;
},
inputKeyUp: function(e) {
    this.model.set({name: $(this.view.el).find('input[type=text]').first().val()});
},
});

So far I’ve gotten around it by using {silent:true} and updating things manually but this creates a mess.

  • 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-28T04:12:17+00:00Added an answer on May 28, 2026 at 4:12 am

    You’re basically getting yourself into a sort of infinite loop situation where you’re binding your view too tightly to your model, and they’re feeding back into each other.

    When a user types into a browser text intput, they’re already “updating the view”. The view already represents the extra text.

    So, when you update the model with those changes, you don’t need the view to update AGAIN, as it already represents the current state.

    So, in these cases, you really do want to use “silent”, as you’re just syncing the model with the current state of the UI, and don’t need the model to inform the view to update.

    As to how often to do this, I’m suspecting on keyup is probably excessive. You may want to do it on blur or, even, on some sort of “save” action.

    As far as the other issue, I’m not sure why adding a class to an element would cause the view to re-render. Are you simply doing something like

    this.$('input[type="text"]').addClass('active')
    

    This shouldn’t trigger your model’s change event and cause render to run again.

    Post comment:

    You need to get more granular then.

    In terms of rendering, break the individual rendering/updating of elements of the view into separate functions.

    Bind property-specific change events (“change:name”) to those more granular rendering functions so that they update the part of the view that you wish to change, but do not update the text input.

    itemView = Backbone.View.extend({
    events: {
        "keyup .itemInput": "inputKeyUp"
    }
    initialize: function(){
        this.model.view = this;
        this.bind('change:name', this.update_other_stuff());
        this.bind('change:selected', this.add_class());
        this.render();
    },
    update_other_stuff: function(){
        this.$('.some_other_thing').html("some desired change");
        return this;
    },
    add_class: function(){
        this.$('input[type=text]').first().addClass('active');
        return this;
    },
    render: function(){
        $(this.el).html( $(ich.itemView( this.model.toJSON() )) );
        return this;
    },
    inputKeyUp: function(e) {
        this.model.set({name: $(this.view.el).find('input[type=text]').first().val()});
    },
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I keep running into this design problem, and I'm not happy with my solution
Here's a problem I keep running into: I have a lot of situations where
In one of my current projects we keep running into this very wierd problem
I'm running into a problem, where I keep getting this error after entering my
I keep running into this error MemCacheError (Broken pipe): Broken pipe on my Rails
This is a design issue I keep running into, so I thought I would
I keep running across this loading image http://georgia.ubuntuforums.com/images/misc/lightbox_progress.gif which seems to have entered into
I keep running into enq: TX - row lock contention, when I run the
I've been using RhinoMocks lately but I keep running into an issue. If I
I'm trying to work through the problems on projecteuler.net but I keep running into

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.