I have nested schemas. Using {{> afQuickField name='work_item' template="myTemplate"}}
outputs the inputs in a very logical way, but for some of my more complex objects this isn't terribly practical. I'd like to set up a template where I can precisely place each input with some other html.
These are also (usually) arrays of objects, so the .autoform-add-item
and .autoform-remove-item
button functionality is very nice and I would like to keep it.
How would I define custom templates for particular nested schemas and call them in my main form?
Have tried
Creating a <template name="afWorkItem_myTemplate">
named like my custom form templates extrapolated from the bootstrap3 form templates. I then try to call it like {{> afWorkItem name='work_item' template="myTemplate"}}
but that did not work at all.
update
I tried to modify my custom afArrayField
template to output different structures based on arrayFieldName
. This seemed a little closer but still no cigar.
Template.afArrayField_autoupdate.helpers({
whichTemplate: function(templateName){
return this.arrayFieldName === templateName;
}
});
Then in afArrayField_autoupdate
template:
{{#if whichTemplate 'address'}}
{{> afQuickField name=this.current.street options=afOptionsFromSchema template="autoupdate" placeholder="schemaLabel"}}
<br />
{{> afQuickField name=this.current.city options=afOptionsFromSchema template="autoupdate" placeholder="schemaLabel"}}
{{> afQuickField name=this.current.state_id options=afOptionsFromSchema template="autoupdate" placeholder="schemaLabel"}}
{{> afQuickField name=this.current.zip options=afOptionsFromSchema template="autoupdate" placeholder="schemaLabel"}}
<br />
{{> afQuickField name=this.current.address_type_id options=afOptionsFromSchema template="autoupdate" placeholder="schemaLabel"}}
{{> afQuickField name=this.current.active_address options=afOptionsFromSchema template="autoupdate" placeholder="schemaLabel"}}
{{else}}
{{> afQuickField name=this.name label=false options=afOptionsFromSchema template="autoupdate" placeholder="schemaLabel"}}
{{/if}}
Which came very close but all of my fields (including ones that are selects if I simply use the afQuickField method in the else block) came out as text inputs.
afWorkItem
input, did you call AutoForm.addInputType to let AutoForm know about it? – markelse
block but not in theif
block... some other things you could try for fun: in theafArrayField
template, what happens if you addtype="select"
to theafQuickField
s, or perhaps change them toafSelect
s? – mark