I have a quick form like so:
{{> quickForm schema=competitorSchema id="newCompetitorForm" type="method" buttonContent="Save Competitor" meteormethod="insertCompetitor" tid=tournament._id }}
This is in a modal popup BTW.
Now in the method code I had a defect and did not specify one of the required fields in the mongo insert operation so what happened was:
This was thrown back to me and I catch this in my onError: auto form hook like so:
onError: function(operation, error, template) {
if(error){
alert(error);
}
}
This could any general error - for any reason BTW.
Alert is not what I want to use here... cause it's not very nice. Collection2 throws "Error: X is required" but I don't really want to parse out the string field name since that's sorta brittle trying to match that with a form key since it seems like X is actually the label.
I can come up with a bunch of work arounds like populating a special div or popping a modal etc but what I really want is for auto form to handle this for me with a generic form level validation error (not a specific key).
Does anyone know if there a nice way built into auto form to display a form level (not field specific error) to the user? I did not see this in the docs.
I see how I can use addInvalidKeys etc for a specific field but what I want to do is use something like addInvalidKeys with no key so it displays a form level error message etc.
You can return whatever you want from the method call return function, so you can return human readable messages as a string or object.
If Alert doesn't work for you, you can use a Modal to put up a nice message.
It's really not much code. You can populate a Session variable when there is an error and add a banner div of some sort.
If you want VALIDATION, then use a SimpleSchema with your autoform and it will work automatically, but that only validates the input matches the Schema, not backend insertion errors etc...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With