2016-11-06 72 views
0

我想使用autoform与流星validatedmethod简单模式和collection2。然而,当我在文本框输入值,我得到:使用aldeed:autoform我得到访问被拒绝

undefined error:403 
errorType:"Meteor.Error" 
message:"Access denied [403]" 
reason:"Access denied" 
stack:"Error↵ at Connection._livedata_result http://localhost:3000/packages/ddp-client.js` 

我的代码使用下面的模板:

{{#autoForm collection=club id="insertClubs" type="insert"}} 
<fieldset> 
    <legend>Add a Club</legend> 
    {{> afQuickField name='name'}} 
    {{> afQuickField name='number'}} 
    {{> afQuickField name='updated'}} 
    {{> afQuickField name='created'}} 
</fieldset> 
<button type="submit" class="btn btn-primary">Insert</button> 
{{/autoForm}} 

然后我使用的是事件帮手听提交并调用validatedmethod:

submit .btn btn-primary'(event, instance) { 
    console.log('test'); 

    insert.call({ 
    name: 'test', 
    number: 3, 
    updated: new Date(), 
    created: new Date() 
    }, (err, res) => { 
    console.log(err); 
    }); 
} 

,这是插入调用本身:

export const insert = new ValidatedMethod({ 
name: 'Clubs.methods.insert', 
validate: Clubs.simpleSchema().validator(), 
run(newClub) { 
    // In here, we can be sure that the newClub argument is 
    // validated. 
console.log('insert new club'); 
if (!this.userId) { 
    throw new Meteor.Error('Clubs.methods.insert.not-logged-in', 
    'Must be logged in to create a club.'); 
} 

Clubs.insert(newClub) 
} 
}); 

我认为这个设置实际上并没有调用我的插入方法,因为我没有看到console.log,但流星返回了错误。任何想法可能是什么问题?

回答

0

搜索并尝试后,我遇到了属性meteormethod和类型属性。配置这似乎调用我的MDG验证的方法,并照顾授权,所以看起来。看得出来说明如何利用这以下:

{{#autoForm collection=club id="insertClubs" type="method" meteormethod="Clubs.methods.insert"}} 
    <fieldset> 
    <legend>Add a Club</legend> 
    {{> afQuickField name='name'}} 
    {{> afQuickField name='number'}} 
    {{> afQuickField name='updated'}} 
    {{> afQuickField name='created'}} 
    </fieldset> 
    <button type="submit" class="btn btn-primary">Insert</button> 
    {{/autoForm}} 

有关详细信息,请参阅:https://github.com/aldeed/meteor-autoform#non-collection-forms