用于数组字段的AutoForm.getFieldValue

时间:2015-01-12 14:02:20

标签: meteor meteor-autoform

我有一个声明为:

的模式
JobSchema = new SimpleSchema({
    responsibilities: {
        type: [String],
        optional: true
    },
    'responsibilities.$': {
        min: 2,
        autoform: {
            afFieldInput: {
                class: 'form-control'
            },
            placeholder: 'E.g. "Build tools according to specifications"'
        }
    }
});

我还有一个UI助手声明为:

Template.registerHelper('currentFieldValue', function (fieldName) {
    return AutoForm.getFieldValue('insertJobForm', fieldName) || '';
});

我有一个模板,我使用这个帮助器来生成表单预览。除了数组之外,它对所有领域都有魅力。什么都没有呈现。有什么想法吗?

{{# if currentFieldValue "responsibilities"}}
    <h3>Responsibilities</h3>
    {{{currentFieldValue "responsibilities"}}}
{{/if}}

1 个答案:

答案 0 :(得分:0)

快速而肮脏的解决方法:

<强> job_create.js

Template.jobCreate.helpers({
    responsibilities: function() {
        var formData = AutoForm.getFormValues('insertJobForm');
        return formData.insertDoc.responsibilities || [];
    }
});

<强> job_create.html

{{# if responsibilities}}
    <h3>Responsibilities</h3>
    {{responsibilities}}
{{/if}}