powmedia / backbone-forms

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

When using data-fields with a single filed the labels are rendered too #421

Closed jdeveloper closed 10 years ago

jdeveloper commented 10 years ago

I wanted to create a custom template and be able to render the forms to.

If using data-editors the errors aren't showen:

<form>
    <h1>My form</h1>

    <h2>My field</h2>
    <div data-editors="my-field">
         <div data-error></div>
    </div>
</form>

So in order to show the errors I changed data-editors for data-fields having the template this way:

<form>
    <h1>My form</h1>

    <h2>My field</h2>
    <div data-fields="my-field"></div>
</form>

But now the label of the field is rendered also. I did a hack by extending de base form and override the default Field template but I think its to hacky, the real good solution would be to override the template of the field inside the same form template. My custom form is:

var MyBackboneForm = Backbone_Form.extend({
        Field: Backbone_Form.Field.extend({
            template: _.template('\
                <div>\
                  <div>\
                    <span data-editor></span>\
                    <div data-error></div>\
                    <div><%= help %></div>\
                  </div>\
                </div>\
              ')
        })
    });

I thing the real good solution would be to be abele to put the form template this way:

<form>
    <h1>My form</h1>

    <h2>My field</h2>
    <div data-fields="my-field">
        <div>
            <div>
                <span data-editor></span>
                <div data-error></div>
                <div><%= help %></div>
            </div>
        </div>
    </div>
</form>

Or render the error div when using the data-editors option

Chrysweel commented 10 years ago

+1.

I want customize the template also.

powmedia commented 10 years ago

For now your solution is the best approach. This is a convention many Backbone plugins have adapted to so I don't think it's too hacky, though one alternative would be to be able to specify a fieldTemplate option on the Form.

On Tue, Sep 30, 2014 at 11:50 AM, Chrysweel notifications@github.com wrote:

+1.

I want customize the template also.

Reply to this email directly or view it on GitHub https://github.com/powmedia/backbone-forms/issues/421#issuecomment-57296273 .

powmedia commented 10 years ago

Closing for now