AutoForms (Non-collection), Meteor Check with simple Schema : Error Handling

I am using simple schema for rendering non-collection Autoform.

My schema

const LocationSchema = new SimpleSchema({
lat: {
type: Number,
optional: false
},
lon: {
type: Number,
optional: false,
},
locality: {
type: String,
optional: false
},
locality_verbose: {
type: String,
optional: true
},
address: {
type: String,
optional: false
},
zip: {
type: Number,
label: “ZIP”,
optional: false
}
});

PlansSchema = new SimpleSchema({
name: {
type: String,
optional: false,
max: 100,
autoform: {
placeholder: ‘Elliot’s Beach’,
}
},
location:{
type: LocationSchema,
label: “Location”
},
price_index: {
type: Number,
label: “Price Index”
},
avg_cost_for_two: {
type: Number,
label: “Average Cost for Two”
},
currency: {
label: “Currency”,
type: String,
allowedValues: [“INR”,"$"],
autoform: {
afFieldInput: {
firstOption: “Select Currency”
}
}
}
}, { tracker: Tracker });


Data from the client

{“name”:“Elliot’s beach”,
“location”:{
“lat”:13.001735,
“lon”:80.273293,
“locality”:“Besant Avenue”,
“locality_verbose”:“Besant Av, Chennai”,
“address”:“Besant Av,Chennai”,
“zip”:600020
},
“price_index”:1,
“avg_cost_for_two”:0,
“currency”:“INR”
}


Server Side Validation using simple schema & Match.test or check

Match.test( dataFromClient, PlansSchema )

or

check ( dataFromClient, PlansSchema )


Whenever I receive data from the client I get validation failed, but not the name of the field for which the validation is failed.
In Check() I get " failed [500] Error: Match error: Unknown key in the field name "
whereas in Match.test(data,pattern) I get false(boolean).


Is my schema is weird for the data provided?, Am I doing it wrong?
why is the validation getting failed?
How can I get for which field the validation is getting filed?

Try PlansScema.validate(doc). Maybe that will give you a more meaningful error.

1 Like

Yes, I believe Match/Check compatibility is only available in the atmosphere package version which is deprecated.

Thank you. I approached it this way.

try{
return planSchema.validate(doc);
}catch (errorObj){
API.utility.response( context, 403, { error: 403, message: errorObj.details } );
}