What is the best way to display an error message caused by calling Autoform MeteorMethod

I have a quick form:

{{> quickForm schema = competitorSchema id = "newCompetitorForm" type = "method" buttonContent = "Save competitor" meteormethod = "insertCompetitor" tid = tournament._id}}

This is a BTW modal surge.

Now, in the method code, I had a defect and I did not specify one of the required fields in the mongo insert operation, so what happened:

  • The check on the client side passed (because I filled in all the required field on the form)
  • When the actual insertion occurred, collector2 threw a valid error saying that field X is missing.

This was thrown back to me, and I will catch this in my onError: startup like this:

onError: function(operation, error, template) { if(error){ alert(error); } } 

It could be any common mistake - for some reason BTW.

The warning is not what I want to use here ... because it is not very nice. Collection2 throws "Error: X required", but I really don't want to parse the string field name, as this sorta fragile tries to match this with the form key, as it seems that X is actually a label.

I can come up with a lot of work around, for example, fill in a special div or add a modal, etc., but I really want the autoform to handle this for me with a general form level check error (and not with a specific key),

Does anyone know if there is a good way built into an automatic form to display the level of a form (rather than a specific error) for 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 without a key so that it displays a level error message, etc.

+5
source share
1 answer

You can return whatever you want from the method callback return function so that you can return human read messages as a string or an object.

If Alert doesn't work for you, you can use Modal to create a nice message.

This is really not much code. You can populate the session variable when there is an error and add some kind of div-div.

If you want VALIDATION, use SimpleSchema with your autoformat, and it will work automatically, but this only confirms that the input matches the circuit and not insert insert errors, etc.

+3
source

Source: https://habr.com/ru/post/1212324/


All Articles