Is posible to append a form element to the parent before render it?

48 views
Skip to first unread message

Patricia Juárez

unread,
Jun 4, 2013, 3:52:45 AM6/4/13
to backbon...@googlegroups.com
Is posible to append a form element to the parent before render it?
Or maybe assign the element to some tag from the parent?
I tryed and It did not work, nothing was rendered.
In several books that behaviour is recommended, to avoid problems with sizes inside the childs.

Thanks


Charles Davison

unread,
Jun 4, 2013, 10:53:42 AM6/4/13
to backbon...@googlegroups.com
Can you provide an example of your code and what you're trying to achieve?  You should be able to attach the form to another parent that is not on the DOM yet, which in some cases is more efficient than applying it directly.


--
You received this message because you are subscribed to the Google Groups "Backbone-forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to backbone-form...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Patricia Juárez

unread,
Jun 5, 2013, 5:59:15 AM6/5/13
to backbon...@googlegroups.com
Hi thank you for yout attention.

I have the next module
define(['./solicitudModelHelena'], function (SolicitudAdmision) {
    return {
        create: function (model, template) {
            return new Backbone.Form({
                schema: {
                    importe_exposicion:     { type: 'Text', title: 'Exposición calculada', editorAttrs: { readonly: 'readonly' }, editorClass: 'cursorAuto' },
                    exposicion_mod:         { type: 'Text', title: 'Exposición modificada', fieldClass: 'no-display', editorAttrs: { tabindex: '3'} },
                    check_modify_exp:       { type: 'Checkbox', title: 'Modificar', editorAttrs: { tabindex: '2'} },
                    tip_operacion:          { type: 'Radio', title: null, editorAttrs: { 'data-type': 'inline-radio' }, options: [
                                                { val: SolicitudAdmision.OPERACION_NORMAL, label: 'Admisión de un cliente' },
                                                { val: SolicitudAdmision.OPERACION_ESPORADICA, label: 'Operación esporádica' }
                                            ]},
                },
                model: model,
                template: template
            });
        }
    }
});

The render of the view use it

          render: function () {
             //render template of the view... 
              this.createModel();
              this.form = SolicitudForm.create(this.model, this.templateForm);
              this.$el.prepend(this.form.el); 
              this.form.render();

              return this;
          }, 


The templateForm is

<section>
    <section>
        <header><h2>Datos</h2></header>
        <div class="column1-5">
            <div data-fields="importe_exposicion"></div>
            <div data-fields="check_modify_exp"></div>
        </div>
        <div class="column1-5">
            <div data-fields="exposicion_mod"></div>
        </div>
        <hr />  
    </section>

    <section>
        <header><h2>Datos </h2></header>
            <div data-fields="tip_operacion"></div>
        <hr />  
    </section>
</section>

It works if I return in create of the form the result of render
define(['./solicitudModelHelena'], function (SolicitudAdmision) {
    return {
        create: function (model, template) {
            return new Backbone.Form({
                schema: {
                   ....
                },
                model: model,
                template: template
            }).render();
        }
    }
});
And after get the form in the render method of the superview do the prepend, so the render is before appending the form el to his parent.

              this.form = SolicitudForm.create(this.model, this.templateForm);
              this.$el.prepend(this.form.el);

The result is what I want, but allways I try to append before render to avoid some problems.

Thanks
Reply all
Reply to author
Forward
0 new messages