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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:34:57+00:00 2026-06-05T14:34:57+00:00

I am creating a form builder application using backbonejs and would like to know

  • 0

I am creating a form builder application using backbonejs and would like to know how load view dynamically
I have a dropdown where i can choose what type of element should be added eg i choose input field. i have some default values that go with every element they are in formstemplate and based on what field is chosen i want to load different html templates.

define([
  'jquery',
  'underscore',
  'backbone',
  'modal',
// Pull in the Collection module from above
  'collections/builder',
  'text!templates/forms/builder.html',
  'text!templates/forms/formsTemplate.html',
  'text!templates/forms/textBox.html',
  'models/builder'

], function ($, _, Backbone, popupModal, attributesCollection, builderTemplate, formsTemplate, inputTemplate, attributesModel) {
    var attributesBuilderView = Backbone.View.extend({
        el: $("#page"),
        initialize: function () {

        },
        render: function () {
            this.loadTemplate();
        },
        loadTemplate: function () {
            var that = this;
            this.el.html(builderTemplate);
        },
        // Listen to events on the current el
        events: {
            "change #attributeType": "loadAttributeTemplate"
        },
        loadAttributeTemplate: function () {
            if ( ($("#attributeType").val()) != '0') {
                $("#attributesArea").append(_.template(formsTemplate, { elementType:              $("#attributeType :selected").text(), _: _ }));
                var template = $("#attributeType").val() + 'Template';
                $(".formElement").html(_.template(template));
            }
        }
    });
    return new attributesBuilderView;
});

here when i run this code i get inputTemplate text in the html rather than template if i put $(“.formElement”).html(_.template(inputTemplate)); it works fine. I just need to know how to load these dynamically

Thanks in advance

  • 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-05T14:35:00+00:00Added an answer on June 5, 2026 at 2:35 pm

    You can place the require call anywhere if you only want to do conditional loading:

    edited (added the function params to the require statement)

    loadAttributeTemplate: function () {
        if ( ($("#attributeType").val()) != '0') {
            require(['text!templates/forms/builder.html',
                'text!templates/forms/formsTemplate.html',
                'text!templates/forms/textBox.html'], 
                _.bind(function(builder, formsTemplate, textBox) {
                    $("#attributesArea").append(_.template(formsTemplate, { elementType:               $("#attributeType :selected").text(), _: _ }));
                    var template = $("#attributeType").val() + 'Template';
                    $(".formElement").html(_.template(template));
                },this);
            );
        }
    }
    

    Note, I also did a _.bind(…,this) to maintain the execution scope. I know that’s not necessarily needed here, but it does come in handy.

    I do this in a few places in my application; especially when I want to load modules only if and when I need them.

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

Sidebar

Related Questions

Using mootools I have a 'builder' class that manufactures form objects, dynamically creating divs
I'm creating a form with dynamically added fields and would like to sum all
I would like to have a go at building a 'Wufoo' type form builder.
I'm creating a form using the form builder in Symfony. I am adding an
I am creating one form in html using table. Which have one Drop down
When creating form elements with Zend (using Zend Studio for Eclipse), I'd like some
I'm creating a dynamic form builder where table rows can be dragged, dropped, reordered
I am creating a form using codeigniter, I wanted to know whether there is
I am dynamically creating a Form that overrides the CreateParams so that I can
I am creating a form, using Zend Form. I have 8 input elements. And

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.