Meteor-Community-Packages / meteor-autoform

AutoForm is a Meteor package that adds UI components and helpers to easily create basic forms with automatic insert and update events, and automatic reactive validation.
MIT License
1.44k stars 328 forks source link

dot notation doesn't fire validation #125

Closed flean closed 10 years ago

flean commented 10 years ago

This is my code and anything with a dot notation causes it to ignore validation using latest version of ui branch with meteor 0.8.0-rc1

<div class="form-group{{#if afFieldIsInvalid name= 'emergency.Name'}} has-error{{/if}}">
  {{> afFieldLabel name= 'emergency.Name'}}
  {{> afFieldInput name= 'emergency.Name'  autocomplete="off" autocapitalize="off" autocorrect="off"}}
  {{#if afFieldIsInvalid name= 'emergency.Name'}}
    <span class="help-block">{{afFieldMessage name= 'emergency.Name'}}</span>
  {{/if}}
</div>
flean commented 10 years ago

Update: It actually ignores required on submit but it does fire validation.

flean commented 10 years ago

I'm really confused on why it will fire the Required on submit for

<div class="col-xs-12 col-sm-6 col-md-6">
  {{> afQuickField name='reference1.Name' autocomplete="off" autocapitalize="off" autocorrect="off"}}   
</div>

and not this (I've tested with max:50 also, makes no difference)

<div class="col-xs-12 col-sm-6 col-md-6">   
  {{> afQuickField name= "emergency.Name" autocomplete="off" autocapitalize="off" autocorrect="off"}}
</div>

model Coffee

@JobsForm = new Meteor.Collection2 "jobsForm",
    schema:
        "emergency.Name":
            type:String
            label:"Name"
        "reference1.Name":
            type:String
            max:50
            label:"Name"
aldeed commented 10 years ago

Does it have anything to do with the space after name=? I think Blaze is tolerant of extra spacing, but I'm not sure what the exact rules are.

flean commented 10 years ago

I've tried with and without the space. The only way I can get it to validate is with ''' validation="browser" '''

aldeed commented 10 years ago

Can you provide a cloneable repo with a minimal reproduction? Or at least post the full code including the full autoform markup and any helpers.

aldeed commented 10 years ago

Also update to 0.8.0-rc5 if you haven't yet, just in case it's something related to blaze.

flean commented 10 years ago

I can't get rc5 to work, IR has a bug in Blaze Layout, I'll post the code in a bit

flean commented 10 years ago

model Coffee

@JobsForm = new Meteor.Collection2 "jobsForm",
    schema:
        date:
            type:Number
            label:"Date Created"
        status:
            type:String
            label:"Status"
        fName:
            type:String
            label:"First Name"
            max:25
        mName:
            type:String
            label:"Middle Name"
            max:25
            optional:true
        lName:
            type:String
            label:"Last Name"
            max:25
        email:
            type:String
            regEx:SimpleSchema.RegEx.Email
        cellPhone:
            type:String
            regEx:/^[2-9]\d{2}-\d{3}-\d{4}$/
            label:"Cell Phone"
        homePhone:
            type:String
            regEx:/^[2-9]\d{2}-\d{3}-\d{4}$/
            label:"Home Phone"
        birthDate:
            type:Date
            label:"Birthdate"
        sex:
            type:String
            label:"Sex"
        "emergency.Name":
            type:String
            label:"Name"
        "emergency.Phone":
            type:String
            regEx:/^[2-9]\d{2}-\d{3}-\d{4}$/
            label:"Phone"
        "address.Street":
            type:String
            label:"Street"
            max:50
        "address.City":
            type:String
            label:"City"
            max:50
        "address.State":
            type:String
            label:"State"
            max:50
        "address.Zip":
            type:String
            regEx:/^[0-9]{5}$/
            label:"Zip"
        startDate:
            type:Date
            label:"Start Date"
        availableDays:
            type:String
            label:"Days Available"
            optional:true
        availableType:
            type:String
            label:"Type of Position"
        "questions.Education":
            type:String
            label:"What is the highest level of Education you have completed?"
            optional:true
        "questions.ComputerSkills":
            type:String
            label:"Computer skill level?"
            optional:true
        "questions.SkillsText":
            type:String
            label:"Please list specific skills you feel may be relevant to the position, or business/technical references:"
            max:500
            optional:true
        "questions.Military":
            type:Boolean
            label:"Do you have Military Experience"
            optional:true
        "questions.AuthorizedForUS":
            type:Boolean
            label:"Are you authorized to work in the U.S."
            optional:true
        "questions.VisitedStore":
            type:Boolean
            label:"Have you have visited our store"
            optional:true
        "questions.StoreExperience":
            type:String
            max:500
            label:"What was your Experience?"
            optional:true
        "questions.WhyUs":
            type:String
            max:500
            label:"Why would you like to work for us?"
            optional:true
        "questions.Convicted":
            type:Boolean
            label:"Have ever been convicted, pleaded guilty to or been placed on deferred adjudication for a felony or misdemeanor (other than minor traffic violations) under your present name or any other? Answering Yes is not an automatic disqualification from employment"
            optional:true
        "questions.ConvictionOutcome":
            type:String
            max:500
            label:"Please provide the date, offense and outcome:"
            optional:true
            custom: ->
                if @field('questions.Convicted').value
                    "required"
        "employment1.Employer":
            type:String
            max:50
            label:"Employer"
            optional:true
        "employment1.Position":
            type:String
            max:50
            label:"Position"
            optional:true
        "employment1.From":
            type:Date
            label:"From"
            optional:true
        "employment1.To":
            type:Date
            label:"To"
            optional:true
        "employment1.Reason":
            type:String
            max:500
            label:"Reason you left?"
            optional:true
        "employment1.Contact":
            type:Boolean
            optional:true
            label:"Can we can contact your Employer?"
        "employment2.Employer":
            type:String
            max:50
            label:"Employer"
            optional:true
        "employment2.Position":
            type:String
            max:50
            label:"Position"
            optional:true
        "employment2.From":
            type:Date
            label:"From"
            optional:true
        "employment2.To":
            type:Date
            label:"To"
            optional:true
        "employment2.Reason":
            type:String
            max:500
            label:"Reason you left?"
            optional:true
        "employment2.Contact":
            type:Boolean
            optional:true
            label:"Can we can contact your Employer?"
        "employment3.Employer":
            type:String
            max:50
            label:"Employer"
            optional:true
        "employment3.Position":
            type:String
            max:50
            label:"Position"
            optional:true
        "employment3.From":
            type:Date
            label:"From"
            optional:true
        "employment3.To":
            type:Date
            label:"To"
            optional:true
        "employment3.Reason":
            type:String
            max:500
            label:"Reason you left?"
            optional:true
        "employment3.Contact":
            type:Boolean
            optional:true
            label:"Can we can contact your Employer?"
        "reference1.Name":
            type:String
            max:50
            label:"Name"
        "reference1.Explain":
            type:String
            max:500
            label:"How long have you known him/her and what type of relationship?"
        "reference1.Contact":
            type:Boolean
            optional:true
            label:"Can we can contact this Reference?"
        "reference2.Name":
            type:String
            max:50
            label:"Name"
        "reference2.Explain":
            type:String
            max:500
            label:"How long have you known him/her and what type of relationship?"
        "reference2.Contact":
            type:Boolean
            optional:true
            label:"Can we can contact this Reference?"
        "reference3.Name":
            type:String
            max:50
            label:"Name"
        "reference3.Explain":
            type:String
            max:500
            label:"How long have you known him/her and what type of relationship?"
        "reference3.Contact":
            type:Boolean
            optional:true
            label:"Can we can contact this Reference?"
        driversLicense:
            type:String
            label:"Drivers License"
        socialSecurity:
            type:String
            regEx:/^\d{3}-\d{2}-\d{4}$/
            label:"Social Security"
        otherLegalNames:
            type:String
            optional:true
            label:"Legal Names"
        otherSocialSecurityNumbers:
            type:String
            optional:true
            label:"Social Security"

@JobsForm.simpleSchema().messages
    'regEx cellPhone':"[label] is not a valid phone Ex. XXX-XXX-XXXX"
    'regEx homePhone':"[label] is not a valid phone Ex. XXX-XXX-XXXX"
    'regEx emergency.Phone':"[label] is not a valid phone Ex. XXX-XXX-XXXX"
    'regEx address.Zip':"This is not a valid 5 digit [label]"
    'regEx socialSecurity':"This is not a valid [label] Number Ex. XXX-XX-XXXX"

HTML

<template name="jobs">
    <div class="container">
        {{#autoForm collection="JobsForm" id="insertJobAutoForm" type="insert" }}
            {{> jobAutoForm}}
            {{> autoFormButtons}}
            <br>
            <br>
            <br>
            <br>
        {{/autoForm}}
    </div>
</template>

<Template name="jobAutoForm">
    <fieldset>
        {{> afFieldInput name= "date" type="hidden"}}
        {{> afFieldInput name= "status" type="hidden"}}
        <hr>
        <div class="row">
                <h3 class="col-xs-12 col-sm-12 col-md-12 text-muted">Your Information</h3>
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-4 col-md-4">
                {{> afQuickField name='fName' autocomplete="off" autocapitalize="off" autocorrect="off"}}
            </div>
            <div class="col-xs-12 col-sm-4 col-md-4">
                {{> afQuickField name='mName' autocomplete="off" autocapitalize="off" autocorrect="off"}}
            </div>
            <div class="col-xs-12 col-sm-4 col-md-4">
                {{> afQuickField name='lName' autocomplete="off" autocapitalize="off" autocorrect="off"}}
            </div>      
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-4 col-md-4">
                {{> afQuickField name='email' autocomplete="off" autocapitalize="off" autocorrect="off"}}
            </div>
            <div class="col-xs-12 col-sm-4 col-md-4">
                {{> afQuickField name='cellPhone' autocomplete="off" autocapitalize="off" autocorrect="off"}}
            </div>
            <div class="col-xs-12 col-sm-4 col-md-4">
                {{> afQuickField name='homePhone' autocomplete="off" autocapitalize="off" autocorrect="off"}}
            </div>
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-4 col-md-4">
                {{> afQuickField name='birthDate' id='birthDate' autocomplete="off" autocapitalize="off" autocorrect="off"}}
            </div>
            <div class="col-xs-12 col-sm-4 col-md-4">
                <div class="form-group{{#if afFieldIsInvalid name= 'sex'}} has-error{{/if}}">
                    {{> afFieldLabel name= 'sex'}}
                    {{#afFieldSelect name="sex"}}
                        <option value="Male">Male</option>
                        <option value="Female">Female</option>
                    {{/afFieldSelect}}
                    {{#if afFieldIsInvalid name= 'sex'}}
                    <span class="help-block">{{afFieldMessage name= 'sex'}}</span>
                    {{/if}}
                </div>
            </div>
        </div>
        <hr>
        <div class="row">
            <h3 class="col-xs-12 col-sm-12 col-md-12 text-muted">Emergency Contact</h3>
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-6 col-md-6">   
                {{> afQuickField name="emergency.Name" autocomplete="off" autocapitalize="off" autocorrect="off"}}
            </div>
            <div class="col-xs-12 col-sm-6 col-md-6">
                {{> afQuickField name='emergency.Phone' autocomplete="off" autocapitalize="off" autocorrect="off"}}
            </div>
        </div>
        <hr>
        <div class="row">
            <h3 class="col-xs-12 col-sm-12 col-md-12 text-muted">Home Address</h3>
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-4 col-md-4">
                {{> afQuickField name='address.Street' autocomplete="off" autocapitalize="off" autocorrect="off"}}
            </div>
            <div class="col-xs-12 col-sm-4 col-md-4">
                {{> afQuickField name='address.Zip' autocomplete="off" autocapitalize="off" autocorrect="off"}}
            </div>
            <div class="col-xs-12 col-sm-4 col-md-4">
                {{> afQuickField name='address.City' autocomplete="off" autocapitalize="off" autocorrect="off"}}
            </div>
            <div class="col-xs-12 col-sm-4 col-md-4">
                {{> afQuickField name='address.State' autocomplete="off" autocapitalize="off" autocorrect="off"}}
            </div>
        </div>
        <hr>
        <div class="row">
            <h3 class="col-xs-12 col-sm-12 col-md-12 text-muted">Availability</h3>
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-6 col-md-6">
                {{> afQuickField name='startDate' id="startDate" }}
            </div>
            <div class="col-xs-12 col-sm-6 col-md-6">
                <div class="form-group{{#if afFieldIsInvalid name= 'availableType'}} has-error{{/if}}">
                    {{> afFieldLabel name= 'availableType'}}
                    {{#afFieldSelect name="availableType"}}
                        <option value="FullTime">Full Time 20hr+</option>
                        <option value="PartTime">Part Time &lt; 20hr</option>
                        <option value="Summer">Summer &lt; 20hr</option>
                        <option value="Winter">Summer &lt; 20hr</option>
                    {{/afFieldSelect}}
                    {{#if afFieldIsInvalid name= 'availableType'}}
                    <span class="help-block">{{afFieldMessage name= 'availableType'}}</span>
                    {{/if}}
                </div>
            </div>
        </div>
        <div class="row">
            <div class="form-group{{#if afFieldIsInvalid name= 'availableDays'}} has-error{{/if}}">
                {{> afFieldInput name= 'availableDays' type='hidden'}}
                <div class="col-xs-12 col-sm-6 col-md-6">   
                    <h4>Availability 10am - 3pm</h4>
                    <div class="checkbox"><label><input type="checkbox" id="chDays1" name="chDays" value="Monday-M" /> Monday</label></div>
                    <div class="checkbox"><label><input type="checkbox" id="chDays2" name="chDays" value="Tuesday-M" /> Tuesday</label></div>
                    <div class="checkbox"><label><input type="checkbox" id="chDays3" name="chDays" value="Wednesday-M" /> Wednesday</label></div>
                    <div class="checkbox"><label><input type="checkbox" id="chDays4" name="chDays" value="Thursday-M" /> Thursday</label></div>
                    <div class="checkbox"><label><input type="checkbox" id="chDays5" name="chDays" value="Friday-M" /> Friday</label></div>
                    <div class="checkbox"><label><input type="checkbox" id="chDays6" name="chDays" value="Saturday-M" /> Saturday</label></div>
                    <div class="checkbox"><label><input type="checkbox" id="chDays7" name="chDays" value="Sunday-M" /> Sunday</label></div>

                </div>
                <div class="col-xs-12 col-sm-6 col-md-6">   
                    <h4>Availability 3pm - 9pm</h4>
                    <div class="checkbox"><label><input type="checkbox" id="chDays8" name="chDays" value="Monday-E" /> Monday</label></div>
                    <div class="checkbox"><label><input type="checkbox" id="chDays9" name="chDays" value="Tuesday-E" /> Tuesday</label></div>
                    <div class="checkbox"><label><input type="checkbox" id="chDays10" name="chDays" value="Wednesday-E" /> Wednesday</label></div>
                    <div class="checkbox"><label><input type="checkbox" id="chDays11" name="chDays" value="Thursday-E" /> Thursday</label></div>
                    <div class="checkbox"><label><input type="checkbox" id="chDays12" name="chDays" value="Friday-E" /> Friday</label></div>
                    <div class="checkbox"><label><input type="checkbox" id="chDays13" name="chDays" value="Saturday-E" /> Saturday</label></div>
                    <div class="checkbox"><label><input type="checkbox" id="chDays14" name="chDays" value="Sunday-E" /> Sunday</label></div>
                </div>
                {{#if afFieldIsInvalid name= 'availableDays'}}
                <span class="help-block">{{afFieldMessage name= 'availableDays'}}</span>
                {{/if}}
            </div>
        </div>
        <hr>
        <div class="row">
            <h3 class="col-xs-12 col-sm-12 col-md-12 text-muted">Questions</h3>
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-6 col-md-6">   
                <div class="form-group{{#if afFieldIsInvalid name= 'questions.Education'}} has-error{{/if}}">
                    {{> afFieldLabel name= 'questions.Education'}}
                    {{#afFieldSelect name="questions.Education"}}
                        <option value="MiddleSchool">Middle School</option>
                        <option value="HighSchool">High School</option>
                        <option value="Associates">Associates</option>
                        <option value="Bachelors">Bachelors</option>
                        <option value="Masters">Masters</option>
                        <option value="PhD">PhD</option>
                    {{/afFieldSelect}}
                    {{#if afFieldIsInvalid name= 'questions.Education'}}
                    <span class="help-block">{{afFieldMessage name= 'questions.Education'}}</span>
                    {{/if}}
                </div>
            </div>
            <div class="col-xs-12 col-sm-6 col-md-6">   
                <div class="form-group{{#if afFieldIsInvalid name= 'questions.ComputerSkills'}} has-error{{/if}}">
                    {{> afFieldLabel name= 'questions.ComputerSkills'}}
                    {{#afFieldSelect name="questions.ComputerSkills"}}
                        <option value="None">None</option>
                        <option value="Basic">Basic</option>
                        <option value="Intermediate">Intermediate</option>
                        <option value="Advanced">Advanced</option>
                        <option value="L337">L337</option>
                    {{/afFieldSelect}}
                    {{#if afFieldIsInvalid name= 'questions.Education'}}
                    <span class="help-block">{{afFieldMessage name= 'questions.ComputerSkills'}}</span>
                    {{/if}}
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12">
                <div class="form-group{{#if afFieldIsInvalid name= 'questions.SkillsText'}} has-error{{/if}}">
                    {{> afFieldLabel name= 'questions.SkillsText'}}
                    {{> afFieldInput name= 'questions.SkillsText' rows="3"  autocomplete="off" autocapitalize="off" autocorrect="off"}}
                    {{#if afFieldIsInvalid name= 'questions.SkillsText'}}
                    <span class="help-block">{{afFieldMessage name= 'questions.SkillsText'}}</span>
                    {{/if}}
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-6 col-md-6">   
                <div class="form-group">
                    {{> afFieldLabel name= 'questions.Military'}}
                    {{> afFieldInput name= 'questions.Military' select="true"  trueLabel="Yes" falseLabel="No"}}
                </div>
            </div>
            <div class="col-xs-12 col-sm-6 col-md-6">   
                <div class="form-group">
                    {{> afFieldLabel name= 'questions.AuthorizedForUS'}}
                    {{> afFieldInput name= 'questions.AuthorizedForUS' select="true"  trueLabel="Yes" falseLabel="No"}}
                </div>
            </div>

        </div>
        <hr>
        <div class="row">
            <div class="col-xs-12 col-sm-6 col-md-6">   
                <div class="form-group">
                    {{> afFieldLabel name= 'questions.VisitedStore'}}
                    {{> afFieldInput name= 'questions.VisitedStore' select="true"  trueLabel="Yes" falseLabel="No"}}
                </div>
            </div>
            <div class="col-xs-12 col-sm-6 col-md-6">   
                <div class="form-group{{#if afFieldIsInvalid name= 'questions.StoreExperience'}} has-error{{/if}}">
                    {{> afFieldLabel name= 'questions.StoreExperience'}}
                    {{> afFieldInput name= 'questions.StoreExperience' rows="3"  autocomplete="off" autocapitalize="off" autocorrect="off"}}
                    {{#if afFieldIsInvalid name= 'questions.StoreExperience'}}
                    <span class="help-block">{{afFieldMessage name= 'questions.StoreExperience'}}</span>
                    {{/if}}
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12"> 
                <div class="form-group{{#if afFieldIsInvalid name= 'questions.WhyUs'}} has-error{{/if}}">
                    {{> afFieldLabel name= 'questions.WhyUs'}}
                    {{> afFieldInput name= 'questions.WhyUs' rows="3"  autocomplete="off" autocapitalize="off" autocorrect="off"}}
                    {{#if afFieldIsInvalid name= 'questions.WhyUs'}}
                    <span class="help-block">{{afFieldMessage name= 'questions.WhyUs'}}</span>
                    {{/if}}
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12"> 
                <div class="form-group">
                    {{> afFieldLabel name= 'questions.Convicted'}}
                    {{> afFieldInput name= 'questions.Convicted' select="true"  trueLabel="Yes" falseLabel="No"}}
                </div>
            </div>
        </div>
        <div class="row">           
            <div class="col-xs-12 col-sm-12 col-md-12"> 
                <div class="form-group{{#if afFieldIsInvalid name= 'questions.ConvictionOutcome'}} has-error{{/if}}">
                    {{> afFieldLabel name= 'questions.ConvictionOutcome'}}
                    {{> afFieldInput name= 'questions.ConvictionOutcome' rows="3"  autocomplete="off" autocapitalize="off" autocorrect="off"}}
                    {{#if afFieldIsInvalid name= 'questions.ConvictionOutcome'}}
                    <span class="help-block">{{afFieldMessage name= 'questions.ConvictionOutcome'}}</span>
                    {{/if}}
                </div>
            </div>
        </div>
        <hr>        
        <div class="row">
            <h3 class="col-xs-12 col-sm-12 col-md-12 text-muted">Employment History (Leave Blank if none)</h3>
        </div>

        <div class="row">
            <h4 class="col-xs-12 col-sm-12 col-md-12 text-info">Current/Previous Job</h4>
        </div>          
        <div class="row">
            <div class="col-xs-12 col-sm-6 col-md-6">
                {{> afQuickField name='employment1.Employer' autocomplete="off" autocapitalize="off" autocorrect="off"}}
            </div>
            <div class="col-xs-12 col-sm-6 col-md-6">   
                {{> afQuickField name='employment1.Position' autocomplete="off" autocapitalize="off" autocorrect="off"}}
            </div>          
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-6 col-md-6">   
                <div class="form-group{{#if afFieldIsInvalid name= 'employment1.From'}} has-error{{/if}}">
                    {{> afFieldLabel name= 'employment1.From'}}
                    {{> afFieldInput name= 'employment1.From' id="From1"}}
                    {{#if afFieldIsInvalid name= 'employment1.From'}}
                    <span class="help-block">{{afFieldMessage name= 'employment1.From'}}</span>
                    {{/if}}
                </div>
            </div>
            <div class="col-xs-12 col-sm-6 col-md-6">   
                <div class="form-group{{#if afFieldIsInvalid name= 'employment1.To'}} has-error{{/if}}">
                    {{> afFieldLabel name= 'employment1.To'}}
                    {{> afFieldInput name= 'employment1.To' id="To1"}}
                    {{#if afFieldIsInvalid name= 'employment1.To'}}
                    <span class="help-block">{{afFieldMessage name= 'employment1.To'}}</span>
                    {{/if}}
                </div>
            </div>              
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12"> 
                <div class="form-group{{#if afFieldIsInvalid name= 'employment1.Reason'}} has-error{{/if}}">
                    {{> afFieldLabel name= 'employment1.Reason'}}
                    {{> afFieldInput name= 'employment1.Reason' rows="3"  autocomplete="off" autocapitalize="off" autocorrect="off"}}
                    {{#if afFieldIsInvalid name= 'employment1.Reason'}}
                    <span class="help-block">{{afFieldMessage name= 'employment1.Reason'}}</span>
                    {{/if}}
                </div>
            </div>  
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12"> 
                <div class="form-group{{#if afFieldIsInvalid name= 'employment1.Contact'}} has-error{{/if}}">
                    {{> afFieldLabel name= 'employment1.Contact'}}
                    {{> afFieldInput name= 'employment1.Contact' select="true"  trueLabel="Yes" falseLabel="No"}}
                    {{#if afFieldIsInvalid name= 'employment1.Contact'}}
                    <span class="help-block">{{afFieldMessage name= 'employment1.Contact'}}</span>
                    {{/if}}
                </div>
            </div>  
        </div>
        <div class="row">
            <h4 class="col-xs-12 col-sm-12 col-md-12 text-info">Second Previous Job</h4>
        </div>      
        <div class="row">
            <div class="col-xs-12 col-sm-6 col-md-6">
                {{> afQuickField name='employment2.Employer' autocomplete="off" autocapitalize="off" autocorrect="off"}}
            </div>
            <div class="col-xs-12 col-sm-6 col-md-6">   
                {{> afQuickField name='employment2.Position' autocomplete="off" autocapitalize="off" autocorrect="off"}}
            </div>              
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-6 col-md-6">   
                <div class="form-group{{#if afFieldIsInvalid name= 'employment2.From'}} has-error{{/if}}">
                    {{> afFieldLabel name= 'employment2.From'}}
                    {{> afFieldInput name= 'employment2.From' id="From2"}}
                    {{#if afFieldIsInvalid name= 'employment2.From'}}
                    <span class="help-block">{{afFieldMessage name= 'employment2.From'}}</span>
                    {{/if}}
                </div>
            </div>
            <div class="col-xs-12 col-sm-6 col-md-6">   
                <div class="form-group{{#if afFieldIsInvalid name= 'employment2.To'}} has-error{{/if}}">
                    {{> afFieldLabel name= 'employment2.To'}}
                    {{> afFieldInput name= 'employment2.To' id="To2"}}
                    {{#if afFieldIsInvalid name= 'employment2.To'}}
                    <span class="help-block">{{afFieldMessage name= 'employment2.To'}}</span>
                    {{/if}}
                </div>
            </div>              
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12"> 
                <div class="form-group{{#if afFieldIsInvalid name= 'employment2.Reason'}} has-error{{/if}}">
                    {{> afFieldLabel name= 'employment2.Reason'}}
                    {{> afFieldInput name= 'employment2.Reason' rows="3"  autocomplete="off" autocapitalize="off" autocorrect="off"}}
                    {{#if afFieldIsInvalid name= 'employment2.Reason'}}
                    <span class="help-block">{{afFieldMessage name= 'employment2.Reason'}}</span>
                    {{/if}}
                </div>
            </div>  
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12"> 
                <div class="form-group{{#if afFieldIsInvalid name= 'employment2.Contact'}} has-error{{/if}}">
                    {{> afFieldLabel name= 'employment2.Contact'}}
                    {{> afFieldInput name= 'employment2.Contact' select="true"  trueLabel="Yes" falseLabel="No"}}
                    {{#if afFieldIsInvalid name= 'employment1.Contact'}}
                    <span class="help-block">{{afFieldMessage name= 'employment2.Contact'}}</span>
                    {{/if}}
                </div>
            </div>
        </div>  
        <div class="row">
            <h4 class="col-xs-12 col-sm-12 col-md-12 text-info">Third Previous Job</h4>
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-6 col-md-6">
                {{> afQuickField name='employment3.Employer' autocomplete="off" autocapitalize="off" autocorrect="off"}}
            </div>
            <div class="col-xs-12 col-sm-6 col-md-6">   
                {{> afQuickField name='employment3.Position' autocomplete="off" autocapitalize="off" autocorrect="off"}}
            </div>              
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-6 col-md-6">   
                <div class="form-group{{#if afFieldIsInvalid name= 'employment3.From'}} has-error{{/if}}">
                    {{> afFieldLabel name= 'employment3.From'}}
                    {{> afFieldInput name= 'employment3.From' id="From3"}}
                    {{#if afFieldIsInvalid name= 'employment3.From' }}
                    <span class="help-block">{{afFieldMessage name= 'employment3.From'}}</span>
                    {{/if}}
                </div>
            </div>
            <div class="col-xs-12 col-sm-6 col-md-6">   
                <div class="form-group{{#if afFieldIsInvalid name= 'employment3.To'}} has-error{{/if}}">
                    {{> afFieldLabel name= 'employment3.To'}}
                    {{> afFieldInput name= 'employment3.To' id="To3"}}
                    {{#if afFieldIsInvalid name= 'employment3.To'}}
                    <span class="help-block">{{afFieldMessage name= 'employment3.To'}}</span>
                    {{/if}}
                </div>
            </div>              
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12"> 
                <div class="form-group{{#if afFieldIsInvalid name= 'employment3.Reason'}} has-error{{/if}}">
                    {{> afFieldLabel name= 'employment3.Reason'}}
                    {{> afFieldInput name= 'employment3.Reason' rows="3"  autocomplete="off" autocapitalize="off" autocorrect="off"}}
                    {{#if afFieldIsInvalid name= 'employment3.Reason'}}
                    <span class="help-block">{{afFieldMessage name= 'employment3.Reason'}}</span>
                    {{/if}}
                </div>
            </div>  
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12"> 
                <div class="form-group{{#if afFieldIsInvalid name= 'employment3.Contact'}} has-error{{/if}}">
                    {{> afFieldLabel name= 'employment3.Contact'}}
                    {{> afFieldInput name= 'employment3.Contact' select="true"  trueLabel="Yes" falseLabel="No"}}
                    {{#if afFieldIsInvalid name= 'employment3.Contact'}}
                    <span class="help-block">{{afFieldMessage name= 'employment3.Contact'}}</span>
                    {{/if}}
                </div>
            </div>  
        </div>       
        <hr>
        <div class="row">
            <h3 class="col-xs-12 col-sm-12 col-md-12 text-muted">References</h3>
        </div>
        <div class="row">
            <h4 class="col-xs-12 col-sm-12 col-md-12 text-info">First Reference</h4>
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-6 col-md-6">
                {{> afQuickField name='reference1.Name' autocomplete="off" autocapitalize="off" autocorrect="off"}} 
            </div>
            <div class="col-xs-12 col-sm-6 col-md-6">   
                <div class="form-group{{#if afFieldIsInvalid name= 'reference1.Explain'}} has-error{{/if}}">
                    {{> afFieldLabel name= 'reference1.Explain'}}
                    {{> afFieldInput name= 'reference1.Explain' rows="3"  autocomplete="off" autocapitalize="off" autocorrect="off"}}
                    {{#if afFieldIsInvalid name= 'reference1.Explain'}}
                    <span class="help-block">{{afFieldMessage name= 'reference1.Explain'}}</span>
                    {{/if}}
                </div>
            </div>          
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12"> 
                <div class="form-group{{#if afFieldIsInvalid name= 'reference1.Contact'}} has-error{{/if}}">
                    {{> afFieldLabel name= 'reference1.Contact'}}
                    {{> afFieldInput name= 'reference1.Contact' select="true"  trueLabel="Yes" falseLabel="No"}}
                    {{#if afFieldIsInvalid name= 'reference1.Contact'}}
                    <span class="help-block">{{afFieldMessage name= 'reference1.Contact'}}</span>
                    {{/if}}
                </div>
            </div>                                          
        </div>
        <div class="row">
            <h4 class="col-xs-12 col-sm-12 col-md-12 text-info">Second Reference</h4>
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-6 col-md-6">
                {{> afQuickField name='reference2.Name' autocomplete="off" autocapitalize="off" autocorrect="off"}} 
            </div>
            <div class="col-xs-12 col-sm-6 col-md-6">   
                <div class="form-group{{#if afFieldIsInvalid name= 'reference2.Explain'}} has-error{{/if}}">
                    {{> afFieldLabel name= 'reference2.Explain'}}
                    {{> afFieldInput name= 'reference2.Explain' rows="3"  autocomplete="off" autocapitalize="off" autocorrect="off"}}
                    {{#if afFieldIsInvalid name= 'reference2.Explain'}}
                    <span class="help-block">{{afFieldMessage name= 'reference2.Explain'}}</span>
                    {{/if}}
                </div>
            </div>          
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12"> 
                <div class="form-group{{#if afFieldIsInvalid name= 'reference2.Contact'}} has-error{{/if}}">
                    {{> afFieldLabel name= 'reference2.Contact'}}
                    {{> afFieldInput name= 'reference2.Contact' select="true"  trueLabel="Yes" falseLabel="No"}}
                    {{#if afFieldIsInvalid name= 'reference2.Contact'}}
                    <span class="help-block">{{afFieldMessage name= 'reference2.Contact'}}</span>
                    {{/if}}
                </div>
            </div>                                          
        </div>
        <div class="row">
            <h4 class="col-xs-12 col-sm-12 col-md-12 text-info">Third Reference</h4>
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-6 col-md-6">
                {{> afQuickField name='reference3.Name' autocomplete="off" autocapitalize="off" autocorrect="off"}} 
            </div>
            <div class="col-xs-12 col-sm-6 col-md-6">   
                <div class="form-group{{#if afFieldIsInvalid name= 'reference3.Explain'}} has-error{{/if}}">
                    {{> afFieldLabel name= 'reference3.Explain'}}
                    {{> afFieldInput name= 'reference3.Explain' rows="3"  autocomplete="off" autocapitalize="off" autocorrect="off"}}
                    {{#if afFieldIsInvalid name= 'reference3.Explain'}}
                    <span class="help-block">{{afFieldMessage name= 'reference3.Explain'}}</span>
                    {{/if}}
                </div>
            </div>          
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12"> 
                <div class="form-group{{#if afFieldIsInvalid name= 'reference3.Contact'}} has-error{{/if}}">
                    {{> afFieldLabel name= 'reference3.Contact'}}
                    {{> afFieldInput name= 'reference3.Contact' select="true"  trueLabel="Yes" falseLabel="No"}}
                    {{#if afFieldIsInvalid name= 'reference3.Contact'}}
                    <span class="help-block">{{afFieldMessage name= 'reference3.Contact'}}</span>
                    {{/if}}
                </div>
            </div>                                          
        </div>
        <hr>
        <div class="row">
            <h3 class="col-xs-12 col-sm-12 col-md-12 text-muted">Agreement (Read Carefully)</h3>
        </div>
        <div class="col-lg-12">
            <p>
                The information on this application is true in all respects. I understand that if I am employed and it turns out that the information I have 
                provided is false or misleading in any respect, I will be subject to discipline, up to and including termination of employment.
            </p>
            <p>
                I authorize {{getCompanyName}} to investigate all statements contained in this Application and obtain copies of my personnel files and information 
                about me from any source.  I hereby release {{getCompanyName}} and its employees, agents, officers and directors, from any and all liability arising 
                out of that investigation, its results or the use of the information obtained.  I authorize {{getCompanyName}} to perform a criminal and driving 
                background check on me, and, for that purpose, I list my Social Security Number, all Social Security Numbers that I have ever used, my name and all names that I 
                have ever used or been known by, and my Driver’s License Number:
            </p> 
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-6 col-md-6">
                {{> afQuickField name='driversLicense' autocomplete="off" autocapitalize="off" autocorrect="off"}}  
            </div>
            <div class="col-xs-12 col-sm-6 col-md-6">   
                {{> afQuickField name='socialSecurity' autocomplete="off" autocapitalize="off" autocorrect="off"}}
            </div>
        </div>
        <div class="row">
            <h5 class="col-xs-12 col-sm-12 col-md-12">Other Legal Identities</h5>
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-6 col-md-6">
                {{> afQuickField name='otherLegalNames' autocomplete="off" autocapitalize="off" autocorrect="off"}}
            </div>
            <div class="col-xs-12 col-sm-6 col-md-6">
                {{> afQuickField name='otherSocialSecurityNumbers' autocomplete="off" autocapitalize="off" autocorrect="off"}}
            </div>
        </div>
        <div class="col-lg-12">
            <p>
                I hereby authorize my former employers, my personal and business references, government agencies and all persons who may be contacted in 
                the course of {{getCompanyName}}'s investigation of me to release all information about my work record, history and performance, the result 
                of any tests, my personnel file, and information concerning my character and suitability for employment in the job(s) I am applying for with 
                {{getCompanyName}}, and I hereby release all such former employers, personal and business references, testing facilities and persons contacted, 
                and their agents, employees, officers and directors, from all liability arising out of their providing such information to {{getCompanyName}}.
            </p>
            <p>
                I understand that this Application will remain active for 30 days, and that if I am not hired within that time period, I must reapply to be considered
                for employment.            
            </p>
            <p>
                I understand and agree that, if I am hired, my employment is <strong> At-Will </strong>  that is, I may quit or my employment may be terminated at any time, 
                with or without cause, for no reason or any reason not otherwise prohibited by law, and with or without notice.  I also understand that my 
                employment At-Will status can only be altered by a written contract signed by the company’s president.
            </p>
            <p>
                By clicking the Agree Button you are signing this document, you will receive a PDF sent to the Email address used in this form. 
                {{getCompanyName}} will contact you in a couple of days.
            </p>    
        </div>

    </fieldset>
</Template>

<Template name="autoFormButtons">
    {{#if newDocMode}}
    <button type="submit" class="btn btn-success insert">Submit</button>
    {{else}}
    <button type="submit" class="btn btn-success update">Update</button>
    {{/if}}
</Template>

Controllers Coffee

Template.jobAutoForm.rendered= ->
    $('#birthDate, #startDate, #From1, #To1,#From2, #To2,#From3, #To3 ').mobiscroll().date
        display: 'modal'
        mode: 'mixed'
        display:'bottom'
        dateOrder: 'M D dd yy'

    $('[name="date"]').val(Date.now())
    $('[name="status"]').val('Pending')

Template.jobAutoForm.helpers
    'getCompanyName': ->
        'XCompany'

Template.jobAutoForm.events
    'change [name=chDays]': (event, template) ->
        availableDays = "";
        _.each template.findAll("[name=chDays]:checked"), (checkbox) ->
            availableDays += checkbox.value + ", "
        if availableDays.length
            availableDays = availableDays.slice(0, -2)

        $(template.find('input[name=availableDays]')).val(availableDays)

    'reset form': (event, template) ->
        $(template.find('input[name=availableDays]')).val("")

Template.autoFormButtons.newDocMode = ->
    !Session.get("selectedJobForm")
aldeed commented 10 years ago

OK, I figured out the issue. If you don't explicitly define an Object key, it is assumed to be optional. This means that you will get "required" errors for its properties only if at least one property is set (i.e., if the object is present, then all of its required properties must be there, but if the object is not present and it's optional, we don't worry about it its properties).

Which is to say, add this to your schema:

emergency:
  type:Object

And add the same for any other objects where you want to make sure the object is present.

A couple other points of feedback, since I was looking at your code:

flean commented 10 years ago

Thanks, that did the trick. I'll try the custom templates.