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

Bootstrap5 clearable file input #43

Closed
millerthegorilla opened this issue Mar 26, 2021 · 0 comments · Fixed by #53
Closed

Bootstrap5 clearable file input #43

millerthegorilla opened this issue Mar 26, 2021 · 0 comments · Fixed by #53

Comments

@millerthegorilla
Copy link

millerthegorilla commented Mar 26, 2021

Hi, I wonder if there should be a field for the bootstrap 5 file input, which has changed since bootstrap 4 to not require the use of javascript, it seems (which helps with CSP), and can be presented in two different forms, small, or large.

https://getbootstrap.com/docs/5.0/forms/form-control/#file-input

I currently have a custom field input, as I am importing bootstrap5 but using crispy bootstrap4. It is the bootstrap4 code, only without the javascript, which is now unnecessary.

{% load crispy_forms_field %}

<div class="{{ field_class }} mb-2">
{% for widget in field.subwidgets %}
{% if widget.data.is_initial %}
<div class="input-group mb-2">
    <div class="input-group-prepend">
        <span class="input-group-text">{{ widget.data.initial_text }}</span>
    </div>
    <div class="form-control d-flex h-auto">
        <span class="text-break" style="flex-grow:1;min-width:0">
        <a href="{{ field.value.url }}">{{ path }}</a>
        </span>
        {% if not widget.data.required %}
        <span class="align-self-center ml-2">
            <span class="custom-control custom-checkbox">
                <input type="checkbox" name="{{ widget.data.checkbox_name }}" id="{{ widget.data.checkbox_id }}" class="custom-control-input"{% if field.field.disabled %} disabled{% endif %} >
                <label class="custom-control-label mb-0" for="{{ widget.data.checkbox_id }}">{{ widget.data.clear_checkbox_label }}</label>
            </span>
        </span>
        {% endif %}
    </div>
</div>
<div class="input-group mb-0">
{% endif %}
    <div class="custom-file{% if field.errors %} is-invalid{%endif%}">
        <label class="custom-file-label text-truncate" for="{{ field.id_for_label }}"></label>
        <input type="{{ widget.data.type }}" name="{{ widget.data.name }}" class="custom-file-input{% if widget.data.attrs.class %} {{ widget.data.attrs.class }}{% endif %}{% if field.errors %} is-invalid{%endif%}"{% if field.field.disabled %} disabled{% endif %}{% for name, value in widget.data.attrs.items %}{% if value is not False and name != 'class' %} {{ name }}{% if value is not True %}="{{ value|stringformat:'s' }}"{% endif %}{% endif %}{% endfor %}>
    </div>
    {% if not widget.data.is_initial %}
    {% include 'bootstrap4/layout/help_text_and_errors.html' %}
    {% endif %}
{% if widget.data.is_initial %}
</div>
<div class="input-group mb-0">
{% include 'bootstrap4/layout/help_text_and_errors.html' %}
</div>
{% endif %}
{% endfor %}
</div>

I am able to instantiate this custom field currently using the following (note the bootstrap5 form-control-lg):

            FileClearInput('image_file', css_class="tinfo form-control form-control-lg"),
@smithdc1 smithdc1 linked a pull request May 31, 2021 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant