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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:25:31+00:00 2026-06-09T07:25:31+00:00

I have a select box that gets populated through a Backbone Collection: class Prog.Views.History

  • 0

I have a select box that gets populated through a Backbone Collection:

class Prog.Views.History extends Backbone.View

  template: JST['backbone/templates/shapes/history']
  tagName: "option"


  initialize: ->
    @model.bind('change:formatted', @render, this);

  render: ->
   $(@el).html(@template(history: @model))
   this

backbone/templates/shapes/history

<option value="<%=history.get('origin')%>"><%=history.get('origin')%></option>

This works great, all the correct data is presented in the select box, but what I would like is for the first option to be “please select” i.e. a placeholder… I thought about injecting a record called “placeholder” into the collection but it seems like a round about way.

This is how I call it:

  appdenDropdown: (history) ->
    console.log("append trigger")
    view = new Prog.Views.History(model: history)
    $('select#history').append(view.render().el)

How can I default this?

  • 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-06-09T07:25:34+00:00Added an answer on June 9, 2026 at 7:25 am

    First thing I don’t think this implementation is gona work properly, I think the result of the render will be something like:

    <option><option value="the_origin">the_origin</option></option>
    

    Attention to the double option.

    A proper solution could be this:

    class Prog.Views.History extends Backbone.View
      tagName: "option"
    
      initialize: ->
        @model.bind('change:formatted', @render, this);
    
      render: ->
        $(@el).attr( "value", this.get( "origin" ) )
        $(@el).html( this.get("origin") )
        this
    

    Not need of template here.

    About the inclusion of the “please select” option.

    Include the “please select” option element hardcoded directly in your HTML into the select element.

    Then not use this.$el.html() to populate the select but this.$el.append(), this will respect the actual default option and it will add the dynamic elements after it.

    Updated

    For example if your select element looks like this:

    <select id="history"></select>
    

    Just make it looks like this:

    <select id="history">
      <option value="0" selected="selected">Please select...</option>
    </select>
    

    As you are using append to add the dynamic option elements the placeholder option element will remain.

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

Sidebar

Related Questions

I have a select box that is being populated dynamically from a database. As
here is my situation. I have a select box that is populated from a
I have a select box that gets generated dynamically. I want to allow users
I have a select box that gets cloned. I want to remove the user's
I have a select box that when I select a country the map gets
I have a select box that needs to submit it's value to a server
I am using chosen.js ( http://harvesthq.github.com/chosen/ ) and I have a select box that
I want to have on my site a single select box that will then
I have a select box on a page that does a post with jQuery
We have a custom JSF component that renders some buttons and a select box

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.