diff --git a/app/client/lib/autoform.coffee b/app/client/lib/autoform.coffee index b32cf08..de2112b 100644 --- a/app/client/lib/autoform.coffee +++ b/app/client/lib/autoform.coffee @@ -1,32 +1,33 @@ # show errors from method-update schema check AutoForm.addHooks null, beginSubmit: -> AutoForm.templateInstanceForForm(@formId)._stickyErrors = {} onError: (formType, error) -> form = @ try fieldErrors = JSON.parse(error.details) catch e # don't care finally if error.reason is "validationErrorQuestionInUse" AutoForm.resetForm form.formId throwError error return - else if !fieldErrors? or fieldErrors.length is 0 + else if (!fieldErrors? or fieldErrors.length is 0) and !error.invalidKeys? throwError error return - JSON.parse(error.details).forEach (e) -> - form.addStickyValidationError(e.name, e.type) + if fieldErrors? + fieldErrors.forEach (e) -> + form.addStickyValidationError(e.name, e.type) # Fix null array items # See https://github.com/aldeed/meteor-autoform/issues/840 AutoForm.addHooks null, before: update: (doc) -> _.each doc.$set, (value, setter) -> if _.isArray(value) newValue = _.compact(value) doc.$set[setter] = newValue return doc diff --git a/app/client/lib/errors.coffee b/app/client/lib/errors.coffee index 49b99fc..5d8cb35 100644 --- a/app/client/lib/errors.coffee +++ b/app/client/lib/errors.coffee @@ -1,49 +1,51 @@ Meteor.startup -> #http://stackoverflow.com/questions/951791/javascript-global-error-handling window.onerror = (msg, url, line, col, error) -> # Note that col & error are new to the HTML 5 spec and may not be # supported in every browser. It worked for me in Chrome. extra = if !col then '' else ' column: ' + col throwError 'Error: ' + msg + '\n\nat: ' + url + '\n\nline: ' + line + extra #throw errors to console throw error # return true, so error alerts (like in older versions of # Internet Explorer) will be suppressed. return true @throwError = (error) -> if typeof error is "string" reason = error else reason = error.reason + if !reason? or reason.length is 0 + reason = "unknown reason" if error.reason? and error.reason is "validationErrorQuestionInUse" swal { title: 'Error' html: true customClass: "text-left" text: """Error: This question is in use. Changing question type, codes, values or selection-mode is therefore not allowed. Your changes will be discarded.

You might: """ type: 'error' showCancelButton: false confirmButtonText: 'OK' } else swal { title: 'Error' text: reason type: 'error' customClass: "text-left" if reason.length > 100 showCancelButton: false confirmButtonText: 'OK' } return