powmedia / backbone-forms

Form framework for BackboneJS with nested forms, editable lists and validation
MIT License
2.17k stars 415 forks source link

Cannot read property 'render' of undefined #536

Closed gsambrotta closed 7 years ago

gsambrotta commented 7 years ago

Hello! I'm keep getting error rendering my Form: The form is correctly create, i can see my template inside the template property of the form. .render() is also a known function but when it come to run this.profileForm.render();, it give the undefined error.

My init function:

this.testTmp = {
        performance:
                    '<form class="form-horizontal">\
                <h2>Performance</h2>\
                <fieldset data-fields="legPress,chestPress,pushUpsTest"></fieldset>\
                <table class="table table-striped">\
                    <tr>\
                        <th>Stage</th>\
                        <th>Time</th>\
                        <th>Speed</th>\
                        <th>Speed</th>\
                        <th></th>\
                    </tr>\
                    <tr>\
                        <td>1</td>\
                        <td>0-3 mins</td>\
                        <td>1.7 mph</td>\
                        <td>10%</td>\
                        <td><div data-fields="firstname"></div></td>\
                    </tr>\
                    <tr>\
                        <td>5</td>\
                        <td>12-15 mins</td>\
                        <td>5.5 mph</td>\
                        <td>15%</td>\
                        <td><div data-fields="lastname"></div></td>\
                    </tr>\
                </table>\
                <fieldset data-fields="email,address"></fieldset>\
            </form>'
        };
    this.profileForm = new Backbone.Form({
      template: _.template(this.testTmp.performance),
      model: this.model,
      validate: true
    });

and then i render the form in the render function:

                this.profileForm.render();
        $('#testPlaceholder').append(this.profileForm.el);

i'm using dustjs template but as you see right now i just save my custom template in a variable.

I search everywhere and try thousend different possible solution but whenever i try to use the custom template, i got Cannot read property 'render' of undefined it might not be the best place to ask for help, but i'm kind of lost. If you know better place where i should write, please let me know (Already try in SO without luck) Maybe someone can help me here?

philfreo commented 7 years ago

Sorry, this isn't the best place for troubleshooting - doesn't look like there's any Backbone-Forms bug based on your report. It looks like somehow this.profileForm is getting cleared before you call render... but it's hard to say for sure what's really going on without seeing more of your code. I suggest posting a more complete version on stackoverflow with the appropriate tags.