【发布时间】:2015-05-24 12:27:39
【问题描述】:
我有一个选择框,询问用户“您是如何得知我们的?”
选项包括 Google、Yelp 和其他(请指定)。
选择“其他”选项并使用autoform验证该文本输入字段的内容时,如何自动启示空白文本输入框?
common.js:
Schema = {};
Schema.contact = new SimpleSchema({
name: {
type: String,
label: "Your Name",
max: 50
},
email: {
type: String,
regEx: SimpleSchema.RegEx.Email,
label: "E-mail Address"
},
subject: {
type: String,
label: "Subject",
max: 1000
},
message: {
type: String,
label: "Message",
max: 1000
},
referral: {
type: String,
allowedValues: ['Google', 'Yelp', 'Other (Please Specify)']
}
});
contact.js:
Template.Contact.helpers({
contactFormSchema: function() {
return Schema.contact;
}
});
contact.html:
{{#autoForm schema=contactFormSchema id="contactForm" type="method" meteormethod="sendEmail"}}
<fieldset>
<legend>Contact Us</legend>
{{> afQuickField name="name"}}
{{> afQuickField name="email"}}
{{> afQuickField name="subject"}}
{{> afQuickField name="message" rows=10}}
{{> afQuickField name="referral" options="allowed"}}
<div>
<button type="submit" class="btn btn-primary">Submit</button>
<button type="reset" class="btn btn-default">Reset</button>
</div>
</fieldset>
{{/autoForm}}
此外,在架构的一部分中:
referral: {
type: String,
allowedValues: ['Google', 'Yelp', 'Other (Please Specify)']
}
如果选择了“其他”选项,我希望能够存储用户直接在referral 下输入的字符串值,而不必仅为该输入创建单独的命名条目。
有什么想法吗?
显然,我更喜欢“Autoform Way”,而不是与 jQuery 或事件侦听器或其他东西一起破解某些东西。
【问题讨论】: