powmedia / backbone-forms

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

subSchema creates a form inside a form #150

Open conoremclaughlin opened 12 years ago

conoremclaughlin commented 12 years ago

Hi,

The plugin is awesome. so I'm doing some basic integration with the library bones. I'm having an issue, though, so if I'm doing something wrong it'd be great to get your help.

Used the npm install for backbone-forms and used Form.setTemplates to add an after the fieldsets within the form:

Form.setTemplates({
    submitForm: '<form class="submit">{{fieldsets}}<input type="hidden"></form>'
});

It kept getting ejected from the form element so I used http://validator.w3.org/check to validate the html and it looks like subSchema is generating another form for the new object fieldset. Compliant parsers ignore the second opening form tag and will just close the parent form tag when it encounters the first close tag. This was closing the other tags and forcing my input element out. Quick excerpt for clarification:

<form class="submit">
........
for="c0_location">Location</label>        <div class="bbf-editor"><div id="c0_location" class="bbf-object" name="location">*<form class="bbf-form">*<fieldset>                <ul><li class="bbf-field">        <label for="c0_location_address">Address</label>        <div class="bbf-editor"><input id="c0_location_address" name="address" type="text" value="" /></div>        <div class="bbf-help"></div>      </li></ul>      </fieldset>*</form>*</div></div>        <div class="bbf-help"></div>      </li></ul>      </fieldset><input type="hidden" /><input type="submit" />*</form>*

I've just flattened my schemas for now, but wanted to give you a heads-up or just see if I was doing anything wrong.

philfreo commented 12 years ago

Can you post your form schema / subSchema? (and if you made any custom editors or whatnot)

daogurtsov commented 11 years ago

I also receive form into form effect but in nested model. i unwraped inner form with jquery but it's ugly approach. I can't figure out why second form rendered?

cthurston commented 11 years ago

Observing the same issue. Below produces a form in a form.

schema: {
        formInForm: { type: 'Object', subSchema:{
            foo: 'Text'}
     }
}
cthurston commented 11 years ago

The fix I guess we could use is on Object and NestedObject editors is:

//this.$el.html(this.form.render().el);
  this.$el.html(this.form.render().$('fieldset:first-child'));

However, this behavior may not be what is desired if rendering the editor independently. I guess we would have to add an option that asks if you want it wrapped in a form element or not.

rjmackay commented 11 years ago

Possible solution for this here: https://github.com/rjmackay/backbone-forms/commit/f8a8e8cca7599056fbe87f3c3e9ebd69cebe9728