I’m evaluating backbone.js, backbone-forms and Rails, and I have some problems …
I have a view where I create a new model and a form, and I want to display this form with other html elements, so I’m using a template.
expedients_new.js.coffee
------------------------
class Globalbackbone.Views.ExpedientsNew extends Backbone.View
template: JST['expedients/new']
render: ->
@form = new Backbone.Form({
model: @model
}).render();
console.log(@model.procedencia)
console.log(@form)
$(@el).html(@template(expedient: @model, form: @form ))
this
This view uses a template, and in this template, I want to render the form there, but I don’t know how to do it …
new.jst.eco
-----------
<h1>BackBones with GlobalWeb</h1>
<h2>Adding New Expedient</h2>
<%=@expedient.date%>
<hr>
<%=@form.el%>
<hr>
<%=@form%>
Thanks in advance,
regards
EDIT
The current browser output where I expect the form is:
[object HTMLFormElement]
The usage instructions indicate that
@formwill be a Backbone view:and that means that
@form.elwill be a DOM element that you need to insert into the DOM:And if you look at the source, you’ll see that
Backbone.Formis aBackbone.Viewsubclass:Your code is trying to treat
@formas though it was a string containing HTML:so you end up with standard stringified version of a DOM element:
[object HTMLFormElement].I think you’ll have better luck if you have something like this in your view:
and in your template:
Then your form should appear after the
<hr>.