Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot add custom data attributes to document field #592

Open
mattr opened this issue Mar 27, 2024 · 0 comments
Open

Cannot add custom data attributes to document field #592

mattr opened this issue Mar 27, 2024 · 0 comments

Comments

@mattr
Copy link
Contributor

mattr commented Mar 27, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant