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

  • Home
  • SEARCH
  • 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 7082797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:05:57+00:00 2026-05-28T07:05:57+00:00

As in the backbone-todolist example,I have a collection of elements. I made 2 views,

  • 0

As in the backbone-todolist example,I have a collection of elements. I made 2 views, one for the list and one for each element. It works great.

However, as I need the elements of the list to be modified, in the view of the element I handle the modify event opening a popup with the colorbox plugin which contains an html form.
The html is dynamically created and passed to the colorbox element.

I use colorbox and backbone-form additional plugins.

Now: the popup IS NOT A CHILD (in the DOM) of my view, so I don’t know how to fire the event on the ‘button submit’ action.

Here is a snippet of the code (omitted unuseful parts):

// ** view of the single collection element
window.listElement = Backbone.View.extend({
    tagName: 'li',

    [...]

    updateElement:function(){
        //creates the update form in a popup menu
        var form=new Backbone.Form({BLA BLA BLA...I TESTED IT, IT WORKS.
            }).render();
        $(form.el).append('<input id="update-btn" type="button" name="updateBtn" value="Update" style="display: block;">');
        self=this;

        //HERE COME THE TROUBLES
        $.colorbox({
            html:form.el,
            [...] /SOME OTHER PARAMS
            }).delegate('#update-btn','click',self.saveEl());
        },
    saveEl:function(){
        console.log("now saving..")},       
        },

What happens is that the saveEl method (or function?, which term would be more correct?) is fired when the popup is opened.

I also tried with a different version of the code:

    initialize: function(){//added this in the initialize function
        _.bindAll(this, "saveEl");
        $('#update-btn').bind('click', this.saveEl());
          },
    updateElement:function(){
        //LIKE BEFORE BUT WITHOUT DELEGATE FUNCTION
        $.colorbox({
            html:form.el,
            [...] /SOME OTHER PARAMS
            });
        },
        saveEl:function(){
           console.log("now saving..")},        
        },

In this second case, the saveEl function is called when the view is created (thus one time for each element of the list).

I know that I colud make a view for the popup, but somEthing says me that it’s too complicated and that there should me a more simple architecture.

The question, indeed, is more general: is it possible to handle events fired by DOM object outside the scope of $(this.el) without creating a view for them?

thanks in advance.

—————–UPDATE:————–

The final version of working code is the following:

// ** view of the single collection element
window.listElement = Backbone.View.extend({
    tagName: 'li',

    [...]

    updateElement:function(){
        //creates the update form in a popup menu
        var form=new Backbone.Form({BLA BLA BLA...I TESTED IT, IT WORKS.
            }).render();
        $(form.el).append('<input id="update-btn" type="button" name="updateBtn" value="Update" style="display: block;">');
        $(form.el).delegate('#update-btn','click',this.saveEl())
        $.colorbox({
            html:form.el,
            [...] /SOME OTHER PARAMS
            });
        },
    saveEl:function(){
        console.log("now saving..")},       
        }
     });
  • 1 1 Answer
  • 3 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-28T07:05:57+00:00Added an answer on May 28, 2026 at 7:05 am

    EDIT:

    $.colorbox doesn’t send back the right html to bind it.

    As you can see, you give to colorbox form.el, so you can directly bind form.el:

    $(form.el).on('click', '#update-btn', self.saveEl);
    // here your colorbox code
    $.colorbox({
        html: form.el,
        // [...] SOME OTHER PARAMS
    });
    

    You should use on now because delegate is an old method: http://api.jquery.com/on/

    ———————-

    Yes, you can handle events fired by DOM object outside the scope of the view, you just need to use $('#your-element') instead this.$('#your-element').

    For your code, it’s normal to trigger saveEl directly because you give to delegate the result of that function, you need to give the pointer of the function like this:

    $.colorbox({
        html: form.el,
        // [...] SOME OTHER PARAMS
    }).delegate('#update-btn', 'click', self.saveEl); // without ()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking back at the Backbone todo list and have a question about the
Newbie backbone question: Context: Building a shopping list with backbone I have a model
My Backbone Collection receives 30 models on fetch(). I have tried newColl=origColl.first(2); to return
If I have a Backbone collection and want to create a copy of that
Here I have a Backbone.js Model - Contact and a Collection - Contacts with
A Backbone Collection and some Views are created in the return function of click()
I am enjoying backbone.js more and more. I desire to have multiple views for
I'm using Backbone.js to render a list of items. THis is working, I have
In Backbone, I have a collection which is populated with some JSON data which
I've finally got my Rails Todo List app to display the Todos using Backbone's

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.