Skip to content

Cannot use custom file input widgets #209

@Noah-Houghton

Description

@Noah-Houghton

I am working on a project where we want to use different file input widgets for different use cases; obviously we'd like to inherit from the existing Django file inputs to reduce code re-use and get Django's file handling for free. However, we discovered that templates/bootstrap5/field.html explicitly disallows this for file inputs, e.g.

{% if field|is_file %}
  {% include 'bootstrap5/layout/field_file.html' %}
{% elif field|is_select %}
  ...

Our current workaround is to manually copy the contents of Django's FileInput and ClearableFileInput to custom input fields which we can then use to create a custom widget; however, this is clearly not a preferable solution. My questions are:

  1. is there a reason to explicitly disallow setting a custom File input?
  2. could support be added to override the file field rendering by e.g. using the same crispy_field approach used for other input types?

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