Custom template autoform not recognized


Hi guys,

I have this custom template that is a slightly modified version of the one in the repo, however it does not seem to be recognized by autoform.

{{#autoForm collection="Programmes" id="insertProgrammeForm" type="insert" template="plain"}}
{{> afQuickField name="name"}}
{{> afQuickField name="description" rows=6}}
{{> afQuickField name="author"}}
{{> afQuickField name="exercises" template="myTemplate"}}
{{> afQuickField name="createdAt" type="hidden" template="myTemplate"}}
<button type="submit">Create programme</button>

As you can see from the above I tried to set the template directly on my quickfield with the name of exercises.

<template name="myTemplate">
<legend>Testing if it works!</legend>
{{#if afFieldIsInvalid}}
    <div class="autoform-array-field-error">
{{#afEachArrayItem minCount=this.atts.minCount maxCount=this.atts.maxCount}}
    <div class="autoform-array-item">
        {{> afQuickField label=false}}
        {{#if afArrayFieldHasMoreThanMinimum name=../ minCount=../atts.minCount maxCount=../atts.maxCount}}
            <button type="button" class="autoform-remove-item">Remove</button>
{{#if afArrayFieldHasLessThanMaximum minCount=this.atts.minCount maxCount=this.atts.maxCount}}
    <div style="margin-top: 20px;">
        <button type="button" class="autoform-add-item" data-autoform-field="{{}}" data-autoform-minCount="{{this.atts.minCount}}" data-autoform-maxCount="{{this.atts.maxCount}}">Add</button>

Is there anything special I have to do to make this work?

thanks in advance!


name must be combination field type and template name according to docs


Hi shock,

Do you have an example of this, or maybe a link to the relevant docs?

I’ve been looking through the docs but cannot find anything related to that



So I figured it out, apparently I had missed this crucial part of the docs:

To define a custom template that is recognized by the AutoForm templates system, simply create a template with the name afType + "_" + templateName. For example, if I want to define a template named "nothing" that can be used by a quickForm to generate nothing:

<template name="quickForm_nothing">

So I changed the name of my template to be afArrayField_nameOfMyTemplate and then referencing to the template directly on my afQuickField

Thanks for helping out :smile: