是否有一个被认为是规范的表单包或者可能类似于最终最终存在于核心中的表单?
在我的搜索中,我提出了两个主要的竞争者,基于活动,彻底和文档(但可能还有其他人):
如果有人查看了这两个,你可以评论一下你可以使用哪一个与另一个相比的原因吗?
答案 0 :(得分:10)
由于这个问题尚未得到解答,我将以“为什么你应该自己做”这个论点来讨论。
表单既显示DOM又验证。我认为Meteor的工具都足够好,不需要在它们之间进行另一次抽象。
考虑一下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
然后我将数据发送到客户端对象以查看它的想法。
答案 1 :(得分:1)
目前没有规范包(Meteor v1.0),似乎问题将留给社区(见roadmap)。
我还要将joshowens:simple-forms添加到您的列表中,这是一个最小的包(因为我喜欢它给予的自由)
我没有尝试过Mesosphere,所以我无法比较,但我认为aldeed:autoform已经获得了更多的牵引力。从 github 和氛围明星来看,它是迄今为止最受欢迎的。我认为主要原因是它与collections2(自动插入,更新等)的完美集成。
答案 2 :(得分:0)
FWIW,我们正在使用autoform和collection2。