powmedia / backbone-forms

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

Subschema doesn't render "title" #419

Closed mromanoff closed 10 years ago

mromanoff commented 10 years ago

my assumption was subschema behaves exact way as a schema. it doesn't render 'title' property for some reason. http://stackoverflow.com/questions/26043035/backbone-forms-subschema-ignore-title-property or http://jsfiddle.net/zelcie/c2c1026r/

robert2d commented 10 years ago

I can confirm this is also not working for the List Editor

fixture_slots:
          title: "Fixture start time(s)"
          type: 'List'
          itemType: 'InlineObject'
          fieldClass: "fixture-occurence"
          editorClass: "fixture-occurence-editor"
          subSchema:
            days:
              title: "Day(s) fixture occurs on"
              type: 'Checkboxes'
              options: Create.WeekdayOptions
              fieldClass: "checkbox-horizontal"
              editorClass: "checkbox-horizontal-editor"
            start_time:
              title: 'Time'
              type: 'TimePicker'
              default: "7:00am"
              step: 5

As I need this fixed ASAP for something i'm working on, i'll try come back with an approach that works to resolve this.

robert2d commented 10 years ago

found the first issue at

//==================================================================================================
//NESTEDFIELD
//==================================================================================================

Form.NestedField = Form.Field.extend({
  template: _.template('\
    <div>\
      <span data-editor></span>\
      <% if (help) { %>\
        <div><%= help %></div>\
      <% } %>\
      <div data-error></div>\
    </div>\
  ', null, Form.templateSettings)

});

where it is not rendering the label for a nested field i have replace the template string with:

Form.NestedField = Form.Field.extend({
  template: _.template('\
    <div>\
      <label for="<%= editorId %>">\
        <% if (titleHTML){ %><%= titleHTML %>\
        <% } else { %><%- title %><% } %>\
      </label>\
      <div>\
        <span data-editor></span>\
        <div class="error-text" data-error></div>\
        <div class="error-help"><%= help %></div>\
      </div>\
    </div>\
  ', null, Form.templateSettings)

});

which now renders the title for the nested field etc.. not sure if this is a suitable solution but it does solve the issue for me.. It is just a straight copy of the template string directly above(https://github.com/powmedia/backbone-forms/blob/master/distribution/backbone-forms.js#L1046)

robert2d commented 10 years ago

It also appears with the addition of the submitButton it has changed the way the forms hierachy is displayed with data-fieldsets now existing in a div inside the main form tag. Will need to update our css to handle this.

mromanoff commented 10 years ago

@robert2d thank you for quick response. Good catch. I didn't try this in my code yet but looking at your solution I'm sure it will work. Thank you man.

Confirmed! it works as expected.

robert2d commented 10 years ago

@mromanoff glad I could help, Im back on track again. would love to know wether the contributors would want this solution, I can package it up and submit it in a pully if needed..

powmedia commented 10 years ago

Thanks, I've updated the template