【发布时间】:2015-07-13 01:21:56
【问题描述】:
在我的 Meteor 应用程序中,我有 TAPi18n 包和 aldeed:autoform。我正在尝试使用 i18n 对占位符字段进行表单验证,但我不知道该怎么做。
所以,我想知道是否可以使用Spacebars 将动态参数(我这样称呼它)传递给模板。我的意思是,在 JS 文件中不使用帮助程序,如下所示:
<template name="Publish">
<div class="col-md-8 col-lg-8 col-md-offset-2 col-lg-offset-2 well">
{{#autoForm collection="Publications" id="insertPublicationForm" type="insert"}}
<fieldset>
<legend>{{_ "publish_title"}}</legend>
<div class="col-md-12 col-lg-12">
<div class="form-group">
{{> afFieldInput name='name' placeholder={{_ "name"}} }}
</div>
<div class="form-group">
{{> afFieldInput name='description' placeholder={{_ "description"}} }}
</div>
<div class="form-group">
{{> afFieldInput name='price' placeholder={{_ "price"}} }}
</div>
</div>
<div class="form-group">
<button type="submit" id="add_publication" class="btn btn-success center-block">{{_ "publish"}}</button>
</div>
</fieldset>
{{/autoForm}}
</div>
</template>
我可以为每个翻译注册一个助手,但我不太喜欢这个想法。
我也知道我可以使用SimpleSchema 中的标签字段,如下所示:
Meteor.startup(function() {
Publications.attachSchema(new SimpleSchema({
name: {
type: String,
label: TAPi18n.__("name"),
max: 200
},
description: {
type: String,
label: TAPi18n.__("description")
},
price: {
type: Number,
label: TAPi18n.__("price"),
min: 0
}
}));
});
然后使用afQuickField 模板代替afFieldInput。
但我不想使用标签,我想使用输入的占位符。
有什么办法吗?
【问题讨论】:
标签: validation templates meteor internationalization spacebars