Custom Meteor autoform模板

时间:2015-03-09 14:40:27

标签: templates meteor meteor-autoform

我有嵌套模式。使用{{> afQuickField name='work_item' template="myTemplate"}}以非常合理的方式输出输入,但对于一些更复杂的对象,这并不是非常实用。我想设置一个模板,我可以使用其他一些html精确地放置每个输入。

这些也是(通常)对象数组,因此.autoform-add-item.autoform-remove-item按钮功能非常好,我想保留它。

我如何为特定的嵌套模式定义自定义模板并在我的主表单中调用它们?

已尝试

创建一个名为我的自定义表单模板的<template name="afWorkItem_myTemplate">,从bootstrap3表单模板中推断出来。然后我尝试将其称为{{> afWorkItem name='work_item' template="myTemplate"}},但这根本不起作用。

更新

我尝试修改自定义afArrayField模板,以根据arrayFieldName输出不同的结构。这似乎有点接近但仍然没有雪茄。

Template.afArrayField_autoupdate.helpers({
  whichTemplate: function(templateName){
    return this.arrayFieldName === templateName;
  }
});

然后在afArrayField_autoupdate模板中:

{{#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}}

其中非常接近,但是我的所有字段(包括如果我只是在else块中使用afQuickField方法而选择的字段)都作为文本输入出现。

1 个答案:

答案 0 :(得分:0)

如果您尝试添加自定义afWorkItem输入类型,则必须致电AutoForm.addInputType让AutoForm了解它。不确定你的模板究竟是什么意思完全不起作用,但这可能是一个原因。 built-in input types的形式有很多例子。