是否有一个表单包被认为是规范的,或者可能类似于最终会出现在核心中的表单包?
在我的搜索中,我根据活动、全面性和文档(但可能还有其他)提出了两个主要竞争者:
如果有人看过这两种方法,您能否评论一下为什么或在哪里可以使用其中一种与另一种?
是否有一个表单包被认为是规范的,或者可能类似于最终会出现在核心中的表单包?
在我的搜索中,我根据活动、全面性和文档(但可能还有其他)提出了两个主要竞争者:
如果有人看过这两种方法,您能否评论一下为什么或在哪里可以使用其中一种与另一种?
由于这个问题尚未得到解答,我将提出“为什么你应该自己做”的论点。
表单既是 DOM 的显示,也是验证。我认为 Meteor 的两种工具都足够好,不需要在它们之间进行另一个抽象。
考虑一下流星给你的东西:你可以为你的对象编写一个类,它本身理解所有的验证和规则。不是通用的“必须是数字方式”,而是以它们存在的复杂方式(必须是素数?)。你可以编写这个类,它可以在客户端和服务器上运行。您应该始终在客户端和服务器上进行验证。验证库如雨后春笋般涌现,因为客户端和服务器(至少)是两种不同的语言。Node/Meteor 到处都是 JS。
为什么不使用这个美妙的功能呢?不要将验证码放在多个地方。将您的数据提供给您的对象,让它在客户端(和服务器)上接受或拒绝它。
例如,我通过组合我自己的模板和一个辅助函数来创建每个文本元素:
表格
{{label_text fname='name' title='Agent Name' placeholder='Formal Name' collection='agent' passthrough='autofocus=autofocus ' }}
{{label_text fname='agentInCharge' title='Agent In Charge' placeholder='Owner' collection='agent' }}
{{label_text fname='phone' title='Phone Number(s)' placeholder='Include Area Code'collection='agent' }}
{{>gps }}
模板
<template name='label_text'>
<div class="row">
<label class="large-3" for="{{fname}}_{{_id}}">{{title}}</label>
<div class="large-8">
<input name="{{fname}}"
id='{{fname}}_{{_id}}'
class="{{fname}}"
value="{{value}}"
data-original="{{value}}"
placeholder="{{placeholder}}"
type="{{type}}" {{passthrough}} />
</div>
</div>
</template>
和一些帮手:
generateField = (options) ->
options.hash.value = options.hash.value or this[options.hash.fname]
# allow for simple params as default
options.hash.title = options.hash.title or options.hash.fname
options.hash.template = options.hash.template or "label_text"
options.hash.placeholder = options.hash.placeholder or options.hash.title
options.hash.type = options.hash.type or 'text'
new Handlebars.SafeString(Template[options.hash.template](options.hash))
Handlebars.registerHelper "label_text", (options) ->
options.hash.collection = options.hash.collection or 'generic'
generateField.call this, options
Handlebars.registerHelper "label_text_area", (options) ->
options.hash.collection = options.hash.collection or 'generic'
options.hash.template = "label_text_area"
options.hash.rows = options.hash.rows or 3
options.hash.columns = options.hash.columns or 40
generateField.call this, options
Handlebars.registerHelper "switch", (options) ->
options.hash.template = "switch"
options.hash.em = options.hash.em || 7
generateField.call this, options
然后我将数据发送到客户端对象以查看它的想法。
目前还没有规范的包(Meteor v1.0),似乎这个问题将留给社区(见路线图)。
我还将joshowens:simple-forms添加到您的列表中,这是一个最小的包(因为我喜欢它提供的自由)
我没有尝试过 Mesosphere,所以我无法比较,但我认为aldeed:autoform已经获得了更多的牵引力。从github和大气之星来看,它是迄今为止最受欢迎的。我相信主要原因是它与 collections2(自动插入、更新等)的完美集成。
FWIW,我们正在使用 autoform 和 collection2。