Autoform: How require email?


#1

Hey everybody,
I’m using the package “autoform” for the first time and want to ask you, how I can require an email address.

In my Schema, I’ve the following options:

emails: {
type: [Object],
minCount:1,
maxCount:1
},
"emails.$.address": {
type: String,
regEx: SimpleSchema.RegEx.Email,
},
"emails.$.verified": {
type: Boolean
}

This is my template:

<div class="item-inner">
<div class="item-input">
    <div class="item-media"><i
            class="icon icon-form-email color-white theme-white"></i></div>
    {{> afFieldInput name='emails.$.address' placeholder='E-Mail-Adresse'}}
</div>

{{#if afFieldIsInvalid name='emails.$.address'}}
    <span class="error-block">{{afFieldMessage name='emails.$.address'}}</span>
{{/if}}

So, if I type in a wrong email address (f.e. “blabla”) I get a validation error - so that part works. But if I leave the field empty, there will be no “email address is required” error. How can I require the mail address and show an error, if the field is empty?


#2

Have you tried to set optional: false ?