在我的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
。
但我不想使用标签,我想使用输入的占位符。
有什么方法可以做到这一点吗?
答案 0 :(得分:0)
好吧,我不知道为什么我之前没有看到它,但我可以在SimpleSchema
中执行此操作:
Meteor.startup(function() {
Publications.attachSchema(new SimpleSchema({
name: {
type: String,
label: TAPi18n.__("name"),
max: 200,
autoform: {
afFieldInput: {
placeholder: TAPi18n.__("name")
}
}
},
description: {
type: String,
autoform: {
afFieldInput: {
placeholder: TAPi18n.__("description")
}
}
},
price: {
type: Number,
min: 0,
autoform: {
afFieldInput: {
placeholder: TAPi18n.__("price")
}
}
}
}));
});
这样我就可以在占位符中使用i18n而无需大量助手。
很抱歉,如果我让别人浪费时间。