How to handle error before insert in autoform hook?

this is my example code

test = () ->
 alert "hello world"

   insert: (doc) ->

i want to ask that is there anyway to prevent “before insert hook” not to run test function when there is an error when submit form. thanks in advance!

The hook you’re looking for is “after”, not “before”. “before” is run before validation is done and is there to give you a chance to modify the form data before anything is going to be done with it.
“after” is where validation has already happened and the function arguments reflect that:

  after: {
    insert: function(err, id) {
      if (err) { ... error! ... return; }
      // validation and actual insert successful!

thanks you i will try that :smile:

1 Like