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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:44:00+00:00 2026-05-30T01:44:00+00:00

So I’m creating reusable UI components that can be easy instantiated later, eg: this.emailInput

  • 0

So I’m creating reusable UI components that can be easy instantiated later, eg:

this.emailInput = new TextInput() {
    label : 'Email Address',
    validators : [validatorFunc, secondValidatorFunc],
    placeholder : 'email@domain.com'
});

Would it make sense for this View to create its own Model that would store a value on keydown and handle the validation? Would it still make sense if there were no validation?

And then more complicated, with an autocomplete:

this.countryInput = new AutocompleteInput() {
    label : 'Country',
    placeholder : 'eg. United States',
    suggestions [ 
        { id : '1', value : 'USA', text : 'United States' },
        { id : 2, value : 'DE', text : 'Germany' },
        ... 
    ]
});

Would it make sense for those suggestions to be stored in a Model of their own that is created by the View as well? Should I also store the selected suggestion in that Model?

It seems like without using a Model I’ve been replicating a lot of the logic the Model gives you automatically.

I’ve also been thinking about having each suggestion be it’s own View that creates its own Model, and have the suggestionListView know about the Collection. Is that how Collection/ListViews work? The ListView knows the Collection and the ItemView knows a Model?

  • 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-30T01:44:01+00:00Added an answer on May 30, 2026 at 1:44 am

    The validators part of your TextInput view are definitely more appropriate for a model. Models in Backbone self-validate, so that buys you a lot. In your keydown scenario, the model would have a persistent value field that stores the current value of the input. You don’t have to explicitly validate against any new values on keydown, you can just directly try to set the model:

    If the model has a validate method, it will be validated before the
    attributes are set, no changes will occur if the validation fails, and
    set will return false.
    — Backbone docs

    So just make sure to define your validate method appropriately.

    Would it still make sense if there were no validation?

    This is an interesting question, since your model/view situation isn’t really typical. What I mean is, it looks like you’re creating form fields for the purpose of creating form fields. If these fields are tied to actual models in your application (i.e., things that are stored in your persistence layer), then those models should be your Backbone models. Otherwise I’m assuming that you actually want a model that means “this is an input field.” But I would say no, probably it wouldn’t make much sense if you didn’t care about validation—because in that case you’re just responding to user events and doing whatever rendering you want, careless about what the actual data is.

    To your second question: I don’t think it buys you much to put the suggestions into their own model. You’re not going to be setting them individually, you’re just retrieving them based on the value of another model.

    To your last point: that is certainly how collections work, but again I don’t think it would buy you much. However, just to illustrate the point, it would look something like this: suggestions would be a collection of Suggestion models; collectionView would be the view that shows the models of suggestions, which would each be a suggestionView that renders a single suggestion. Again, this would be total overkill in this situation IMO. The only reason to do it would be if you actually care about each individual suggestion, i.e., if you want to respond to events on it, or for some reason save its data. I don’t think you do, though.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.