Skip to content

Cannot add custom data attributes to document field #592

@mattr

Description

@mattr

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions