Meteor-Community-Packages / meteor-simple-schema

Meteor integration package for simpl-schema
https://github.com/Meteor-Community-Packages/meteor-simple-schema
MIT License
920 stars 162 forks source link

Two fields must be equal #693

Closed nathanprins closed 7 years ago

nathanprins commented 7 years ago

I want to use SimpleSchema for checking if the email and emailCheck fields in my React form are indeed identical. But for some reason I can't seem to find this option in the docs, even though this seems like a logical thing to exist.

This is what I got right now:

export default UserSchema = new SimpleSchema({
    firstName: {
        type: String,
        label: 'First Name',
        max: 100
    },
    lastName: {
        type: String,
        label: 'Last Name',
        max: 100
    },
    email: {
        type: String,
        regEx: SimpleSchema.RegEx.Email,
    },
    verifyEmail: {
        type: String,
        regEx: SimpleSchema.RegEx.Email,
    }
});

what I'd like to have is something like:

export default UserSchema = new SimpleSchema({
    firstName: {
        type: String,
        label: 'First Name',
        max: 100
    },
    lastName: {
        type: String,
        label: 'Last Name',
        max: 100
    },
    email: {
        type: String,
        regEx: SimpleSchema.RegEx.Email,
    },
    verifyEmail: {
        type: String,
        regEx: SimpleSchema.RegEx.Email,
        equals: email  // <<<<-------
    }
});

Am I missing something?

aldeed commented 7 years ago

There is not a specific property for it but there are instructions here: https://github.com/aldeed/node-simple-schema#validate-one-key-against-another