unclecheese

Seems to me you’d just want:

  1. <Dropzonne canFileUpload={async () => {return await myCallback()}} />
unclecheese

Sorry, what kind of validation are you trying to do?

JZubero

Don't think so. This is where the hook gets evaluated. If canFileUpload is a fn a boolean value is expected 🤷‍♂️

  1. /**
  2.   * Custom validation hook for the Dropzone library. Invoking the done() callback
  3.   * invalidates the upload.
  4.   *
  5.   * @param {object} file
  6.   * @param {function} done
  7.   * @returns {*}
  8.   */
  9. handleAccept(file, done) {
  10. // check with parent if there are other forms of validation to be done
  11. if (typeof this.props.canFileUpload === 'function' && !this.props.canFileUpload(file)) {
  12. return done(i18n._t(
  13. 'AssetAdmin.DROPZONE_CANNOT_UPLOAD',
  14. 'Uploading not permitted.'
  15. ));
  16. }
  17.  
  18. if (!this.props.canUpload) {
  19. return done(i18n._t(
  20. 'AssetAdmin.DROPZONE_CANNOT_UPLOAD',
  21. 'Uploading not permitted.'
  22. ));
  23. }
  24.  
  25. return done();
  26. }
unclecheese
  1. handleAccept = async () => { const response = await callURL(file); return response.isAllowed }
unclecheese

handleAccept won’t accept an async callback?

JZubero

Hi Aaron! Thanks for RE. Got it, I'll take a look @silverstripe/webpack-config. In the meantime I've added the following to my webpack config:

  1. externals: {
  2. 'lib/Injector': 'Injector'
  3. }

Since we are on that topic: I was wondering what the best approach was to hook into the UploadField and/or AssetDropzone components when a file was already picked, but not uploaded. I need to do some client-sided validation before I grant the actual upload. The handleAccept prop of the Dropzone component seemed to qualify for this first. But since the validation needs to happen async I can not use it for my purposes 😕

Do you happen to have any suggestion for this? Thanks!

unclecheese

The basic idea is that we have multiple modules all with their own bundles, and sharing between them can’t be done without some pretty major hacks. 🙂

unclecheese

Hi, @JZubero.. lib/injectoris a global provided by admin. You’ll need to install `@silverstripe/webpack-config`` and use the pre-configured webpack to work with SS modules.

JZubero

Hi all. Anyone ever extended a framework field with custom React logic as described here: https://docs.silverstripe.org/en/4/developer_guides/customising_the_admin_interface/how_tos/customise_react_components/? Just wondering where I have to import lib/injector from 🤔 Found this repo https://www.npmjs.com/package/@silverstripe/react-injector but it does not seem to do the trick. Any hints are very much appreciated!

Show 2 attachment(s)
docs.silverstripe.org  
Customising React components

Developer and user documentation for the Silverstripe CMS and framework.

npm  
@silverstripe/react-injector

A dependency injection layer for sharing components between React applications

Hide attachment content