0
votes

Below is my nested schema. name.first is required. but when I submit the form it not validating, it allows empty string. did I missed anything? or How to fix this issue?

    Schema.UserProfile = new SimpleSchema({
      'name.first': {
        type: String,
        max: 50,
        label: "First name"
      },
      'name.last': {
        type: String,
        optional: true,
        max: 50,
        label: "Last name"
      }
    });

    Schema.User = new SimpleSchema({
     profile: {
        type: Schema.UserProfile,
        optional: true
      },
    });

Meteor.users.attachSchema(Schema.User);

form:

{{#autoForm id="profile" type="method-update" meteormethod="updateProfile" schema=userSchema doc=currentUser collection=Users}}
        {{> afQuickField name="profile.name.first" autofocus='' formgroup-class="col-xs-6"}}
        {{> afQuickField name="profile.name.last" formgroup-class="col-xs-6"}}
{{/autoForm}}
1
Your schema and form look correct. I copy/pasted it in a small project and it works as expected. Clearing the firstname field shows message 'First name is required'. Is the profile.name.first field really empty is you check it in mongoDB? And you have a templatehelper Users that returns Meteor.users right? - Jos Harink
Thanks @JosHarink. I made a mistake in Users templatehelper. THANKS a lot - Ramesh Murugesan
@JosHarink Have you tried to submit without entering any data? - Ramesh Murugesan
No, I sticked to your question, checked whether the schema validated and that's it. And I made a fake updateProfile method. Why? - Jos Harink

1 Answers

0
votes

I have checked your schema Schema is looking good but you will have add object for the name.

Schema.UserProfile = new SimpleSchema({
  'name': {
   type: Object,
   optional: false
  },
  'name.first': {
    type: String,
    max: 50,
    label: "First name"
  },
  'name.last': {
    type: String,
    optional: true,
    max: 50,
    label: "Last name"
  }
});