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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:45:02+00:00 2026-05-25T12:45:02+00:00

For example, something simple like the function of a login button. Would this go

  • 0

For example, something simple like the function of a login button. Would this go in the router, view, or model?

Trying to grok this! Any other explanation of what goes where would be great.

Thanks!

  • 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-25T12:45:03+00:00Added an answer on May 25, 2026 at 12:45 pm

    My general approach is to have the model’s run the real logic of the application, while the views act as coordinators between the models and the HTML / interaction with the user.

    In the case of a login button, you could have something simple like this:

    <form>
      username: <input id="username">
      password: <input id="password">
      <button id="login">Login</button>
    </form>
    

    with this view:

    LoginView = Backbone.View.extend({
      events: {
        "click #login": "login"
      },
      login: function(e){
        e.preventDefault();
        model.set({
          username: this.$("#username").val(),
          password: this.$("#password").val()
        });
        model.login();
      }
    });
    

    and a model that looks something like this:

    User = Backbone.Model.extend({
      login: function(){
        var self = this;
        $.post("/user/login", 
          this.toJSON(),
          function(data){
            if (data.loggedIn){
              self.trigger("loggedIn", self);
            }
          }
        });
      }
    });
    

    This is a very simple example and doesn’t cover many of the edge cases or what to do once you have logged in, of course. But at this point, you’ll have the ability to listen to the user model’s “loggedIn” event and have your application respond appropriately.

    there are some edge-cases that you’ll want to cover, such as not allowing someone to log in if they haven’t supplied both a username and password. i’ve got a couple of blog posts that cover this:

    http://lostechies.com/derickbailey/2011/06/15/binding-a-backbone-view-to-a-model-to-enable-and-disable-a-button/

    http://lostechies.com/derickbailey/2011/08/14/enabling-and-disabling-a-button-with-backbone-modelbinding/

    and you may want to employe an “event aggregator” to raise a “user:loggedIn” event instead of having the user model directly raise that event. I’ve covered the user of an event aggregator related to coordinating multiple views, here:

    http://lostechies.com/derickbailey/2011/07/19/references-routing-and-the-event-aggregator-coordinating-views-in-backbone-js/

    …

    of course, my style of development is only one possible style with backbone. i’d recommend searching around google and the backbone documentation to look at additional examples.

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

Sidebar

Related Questions

For example can i have something like this: public static void SAMENAME (sameparameter n)
If for example, I have some jQuery doing something simple like: $(div).fadeIn('fast'); $(div).html('Foo'); That
What's an example of something dangerous that would not be caught by the code
Poppler is a classic example of something without documentation that you would prefer be
I have URL like: http://example.com#something , how do I remove #something , without causing
I have some URLs, like http://www.example.com/something?param1=value1&param2=value2&param3=value3 and I would like to extract the parameters
I commonly see people setting $_SESSION variables as $_SESSION['example']=$_REQUEST['something']; $example=$_SESSION['example']; is this redundant? I
I'm trying to redirect requests for a wildcard domain to a sub-directory. ie. something.blah.example.com
I have an application wherein I would like a function to be executed in
In C, I can put a log printf inside a function like this: void

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.