meteor-autoform-file icon indicating copy to clipboard operation
meteor-autoform-file copied to clipboard

Adding hooks

Open jankapunkt opened this issue 3 years ago • 1 comments

I have a suggestion:

I am still using this and I came to some limits I'd like to solve with some hooks:

picture: {
  type: String,
  autoform: {
    afFieldInput: {
      type: 'fileUpload',
      collection: 'Images',
      hooks: {
        onProgress: () => {}, // while in progress
        onComplete: () => {}, // progress === 100%
        onError: err => {}, // there was an upload error
        onRemove: fileId => {}, // user wants to delete the uploaded file
        onRemoved: () => {}, // the file has been removed
      }
    }
  }
}

The reasons are simple:

  • disable form submit/cancel until file has been uploaded
  • let users remove their uploaded file by using a custom Meteor method (because the default remove is disabled)
  • custom way of communicating upload errors to the user

jankapunkt avatar Apr 12 '22 06:04 jankapunkt

Even easier would be to just pass the Upload context from insert:

picture: {
  type: String,
  autoform: {
    afFieldInput: {
      type: 'fileUpload',
      collection: 'Images',
      hooks: {
        onUpload: (file, uploadCtx) => {}, // hook into upload ctx
        onRemove: fileId => {}, // user wants to delete the uploaded file
      }
    }
  }
}

jankapunkt avatar Apr 12 '22 06:04 jankapunkt