The custom govuk_document_field defines a stimulus controller and actions to provide additional functionality over the default file field behaviour; however, we cannot (easily) amend this in a given form to include additional stimulus behaviour.
Use case
I want to use javascript to validate the size of a file before it is uploaded.
We can work around this limitation by inheriting from the original document field controller:
import KoiDocumentFieldController from "koi/controllers/document_field_controller";
export default class DocumentFieldController extends KoiDocumentFieldController {
onUpload(e) {
super.onUpload(e);
// custom code goes here
}
}
This only allows us to hook into existing actions, and not to define any custom behaviours, however.
Alternatively, we can use the base govuk_file_field; however, the trade-off is that we lose the additional functionality that Katalyst has invested in the file upload UX.
The custom
govuk_document_field
defines a stimulus controller and actions to provide additional functionality over the default file field behaviour; however, we cannot (easily) amend this in a given form to include additional stimulus behaviour.Use case
I want to use javascript to validate the size of a file before it is uploaded.
We can work around this limitation by inheriting from the original document field controller:
This only allows us to hook into existing actions, and not to define any custom behaviours, however.
Alternatively, we can use the base
govuk_file_field
; however, the trade-off is that we lose the additional functionality that Katalyst has invested in the file upload UX.