Can Autoform handle styling and internationalization for nested schemas?


#1

I’m using the following packages:

tap:i18n
aldeed:autoform
aldeed:collection2
gwendall:autoform-i18n

I’ve got a “locations” schema that looks like this:

SimpleSchema.LocationsSchema = new SimpleSchema({
  _id: {
      type: String,
      regEx: SimpleSchema.RegEx.Id,
      autoValue: function() {
          return Random.id();
      },
      autoform: {
          type: "hidden"
      }
  },
  location: {
    type: String,
    max: 12
  },
  parentLocation: {
    type: String,
    optional: true
  }
});

I’ve got a schema for Events that contains the following (only including the relevant pieces):

SimpleSchema.EventsSchema = new SimpleSchema({
  name: {
     type: String,
     max: 30,
     optional: false
  }
  locations: {
      type: [SimpleSchema.LocationsSchema],
      minCount: 2,
      maxCount: 6
  }
});

I initialize i18n with the following: (the documents creating these schema nodes exist elsewhere)

Meteor.startup(function () {
  SimpleSchema.LocationsSchema.i18n("schema-locations");
  SimpleSchema.EventsSchema.i18n("schema-events");
});

Using the following template definition:

{{> afQuickField template="bootstrap3-horizontal" label-class="col-sm-3" input-col-class="col-sm-9" name='eventName'}}
{{> afArrayField template="bootstrap3-horizontal" label-class="col-sm-3" input-col-class="col-sm-9" name='locations'}}

I am able to see the international labels for both fields, however, the array elements inside the locations template do not have the correct labels, but instead use the label derived from their node (e.g. “Parent Location” instead of the translated value). I found this issue with gwendall:autoform-i18n here: https://github.com/gwendall/meteor-autoform-i18n/issues/8 where it’s reported that arrays do not display the internationalization label. After a bit of debugging, it seems the problem lies in the autoform templates rather than in the gwendall:autoform-i18n package. Aside from a null pointer error (resolving that did not fix the issue), everything seems to boil down to this in the afEachArrayItem template

<template name="afEachArrayItemCustom">
  {{! This is a block component and doesn't render anything visible, so no customizable template is needed for this}}
  <label {{afFieldLabelAtts}}>{{#if this.labelText}}{{this.labelText}}{{else}}{{afFieldLabelText name=this.name}}{{/if}}</label>
  {{#with innerContext}}

    {{#each this}}
    {{#if this.removed}}
    <input type="hidden" name="{{this.name}}" data-schema-key="{{this.name}}" data-null-value="true" value="">
    {{else}}
    {{> Template.contentBlock this}}
    {{/if}}
    {{/each}}
  {{/with}}
</template>

So… That’s the background, here’s my question… What is {{> Template.contentBlock this}} and how can I manipulate the values piped into this object… or… how can I change what’s in it’s place to create a template that lets me style arrays?