您好我的客户端错误人口有问题。 客户端/ 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没有显示:\ 有任何想法吗?
答案 0 :(得分:0)
我相信你必须传递一个包含无效字段列表的数组,例如:
Booklist.simpleSchema().namedContext('insertBooklist').invalidKeys([{name: 'title', 'type': 'required'}])