У меня есть поле выбора, которое спрашивает пользователя: «Как вы узнали о нас?»
Возможные варианты: Google, Yelp и Другое (укажите).
Как заставить Autoform отображать пустое поле ввода текста, когда выбран параметр «Другое», а также использовать 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
, и не создавать отдельную именованную запись только для этого ввода.
Любые идеи?
Очевидно, я бы предпочел сделать это «способом автоформовки», а не взламывать что-то вместе с jQuery или прослушивателем событий или чем-то еще.