meteor/validation-error

[Enhancement] Form-level errors

neil-s opened this issue · 4 comments

Is there a plan to support form-level, rather than field-level errors? Alternatively, is there a community standard alternative to validation-error for doing that? I want to show an error if the user submitting a form (specifically, a quickForm) is not authorized (not in the correct role) to submit that form, and can see no easy way to do this.

I don't understand the term "form-level error". If you want to throw the "not-authorized" error then just throw regular Meteor.Error

A regular Meteor.error doesn't automatically get picked up by a quickForm (from the Autoform package) and shown to the user. It seems like a common enough flow to not warrant writing custom handling code for.

Oh ok so it's question to @aldeed

@neil-s you can set up a global hook for all autoforms in your app:

AutoForm.addHooks(null, {
  onError: function (type, error) {
    if (ValidationError.is(error)) {
      this.validationContext.addInvalidKeys(error.details);
    }
  },
});

I may eventually update autoform to do this automatically when your form type is "method" or "method-update"