【问题标题】:How to use placeholder with Meteor AutoForm select2?如何在 Meteor AutoForm select2 中使用占位符?
【发布时间】:2016-02-08 12:46:16
【问题描述】:

我正在使用 AutoForm 包,包括 Meteor 的 select2 扩展。

aldeed:autoform

aldeed:autoform-select2

autoform-select2 上的文档告诉我,我可以像这样设置 use select2Options:

{{> afQuickField name='finalReviewerComments'select2Options=select2Options}}

我的架构:

finalReviewerComments: {
    type: String,
    max: 20,
    autoform: {
        options: [
            {label: "Good", value: 0},
            {label: "9: Grammar/spelling/formatting/readability", value: 9},
            {label: "8: Not a finding", value: 8},
            {label: "7: Information missing", value: 7},
            {label: "6: Repeated/combined finding", value: 6},
            {label: "5: FAQ requirements", value: 5},
            {label: "4: Multiple findings in one", value: 4},
            {label: "3: Context missing", value: 3},
            {label: "2: Country/page number error", value: 2},
            {label: "1: Misinterpretation", value: 1}
        ],
        type: "select2"
    },
    optional: true
}

我尝试在 autoform 中将其添加到我的架构中:

afFieldInput: {
    select2Options: {
        placeholder: "Imaginary text here"
    }
}

并使用文档中指出的辅助函数 select2Options:

Template.finalReview.helpers({
    select2Options: function () {
        return {placeholder: "Final Review Comments"};
    }
});

这两个选项都不起作用。我怎样才能让它工作?表单呈现时我想要一个空的 select2 输入框。

编辑:澄清一下:{allowclear: true} 也不起作用。

【问题讨论】:

  • 您能尝试使用afFieldInput 代替afQuickField 元素吗?

标签: javascript meteor jquery-select2 meteor-autoform


【解决方案1】:

占位符默认为空白。如文档所述,要添加实际值,这是可行的:

帮助文件:

Template.testTemplate.helpers({
    select2Options: function () {
        return {placeholder: "Find a dataset"};
    }
})

模板文件:

<template name="testTemplate">
    {{#autoForm id='addDatasetForm' schema=datasetsSchema type='normal' class="form-horizontal" validation='keyup'}}
        {{> afQuickField class='select2 select-css' name=dataset_name options=getDatasets size=10 select2Options=select2Options}}
    {{/autoForm}}
</template>

它返回:

虽然现在我已经提供了这个答案,但第一次渲染模板时占位符似乎没有出现。这个特定的字段是数组字段的一部分,只有在我删除然后重新添加一个元素到数组字段后才会显示。

【讨论】:

    猜你喜欢
    • 2015-10-22
    • 2023-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-04
    • 2014-03-13
    • 2018-10-25
    • 1970-01-01
    相关资源
    最近更新 更多