嗨,我有一个关于客户端错误填充的问题。客户端/html
<template name="add_book">
{{#autoForm collection="booklist" id="insertBooklist" type="insert"}}
<div class="forms">
{{>afFieldLabel name="title"}}
{{> afFieldInput name='title' autofocus='' placeholder="schemaLabel" class="input-text"}}
{{#if afFieldIsInvalid name='title' autoform=..}}
<span class="help-block">{{{afFieldMessage name='title' autoform=..}}}</span>
{{/if}}
</div>
<a href="{{pathFor 'user_board'}}" class="butyellow"><span>Save</span></a>
{{/autoForm}}
</template>作为客户端JS,我有下一步:
AutoForm.setDefaultTemplate('plain');
Template.add_book.events({
'click .butyellow': function (event, template) {
event.preventDefault();
event.stopPropagation();
title = template.find("input:text[name=\"title\"]");
var book = {title: title.value}
Meteor.call('add_book', book,
function(error, id) {
if (error)
{
console.log(error);
}
else {
title.value = '';
alert("Does is good:" + id);
}
});
}
});在服务器上:
Meteor.methods({
add_book: function (data) {
Booklist.insert(data,function(err, res) {
if (err) {
throw new Meteor.Error(403, Booklist.simpleSchema().namedContext('insertBooklist').invalidKeys());
}
return res;
});
}
});有了所有这些,我可以把错误放在控制台上,但由于某种原因,afFieldMessage没有显示:\有什么想法吗?
发布于 2015-05-09 23:32:30
我认为您必须传递一个包含要失效的字段列表的数组,例如:
Booklist.simpleSchema().namedContext('insertBooklist').invalidKeys([{name: 'title', 'type': 'required'}])https://stackoverflow.com/questions/25351549
复制相似问题