Make progress with automatic form field for model autocompletion

This commit is contained in:
2021-12-31 22:29:47 +01:00
parent 258fd1747c
commit a0775a69ca
5 changed files with 97 additions and 17 deletions

View File

@@ -119,9 +119,11 @@
</div>
</div>
</div>
{{comp_form|crispy}}
<form action="" method="post">
{% csrf_token %}
{{comp_form|crispy}}
<input type="submit" name="submit-edit-component" value="Submit">
</form>
</div>
{% if component.get_resolved_image %}

View File

@@ -0,0 +1,28 @@
<div class="dropdown">
<input autocomplete="off" data-ac-url="{{custom.search_url}}" data-bs-toggle="dropdown" class="form-control{% if widget.errors %} is-invalid{% endif %}" type="text" placeholder="Search...">
<div class="d-flex align-items-center" id="{{widget.attrs.id}}-dflex-container">
{% if custom.current_instance %}
{% if custom.image_field_name %}
<div class="flex-shrink-0">
{% if custom.image %}
<img src="{{custom.image.url}}" style="max-width:64px;max-height:64px;" class="mr-3">
{% else %}
{% load static %}
<img src="{% static 'css/icons/card-image.svg' %}" style="width:64px;max-height:64px;" class="mr-3">
{% endif %}
</div>
{% endif %}
{% endif %}
<div class="flex-grow-1 ms-3">
{% if custom.current_instance %}
{{custom.current_instance}}
{% else %}
<span class="text-secondary">None selected</span>
{% endif %}
</div>
</div>
<ul id="{{widget.attrs.id}}-ac-ul" class="dropdown-menu">
</ul>
<input type="hidden" {% if widget.value != None %}value="{{widget.value}}"{%endif%} name={{widget.name}}>
</div>

View File

@@ -1,7 +0,0 @@
<div class="dropdown">
<input autocomplete="off" data-bs-toggle="dropdown" class="form-control{% if widget.errors %} is-invalid{% endif %}" type="text" {% if widget.value != None %}value="{{widget.value}}"{%endif%}
{% for name, value in widget.attrs.items %}{% if value is not False and name != 'id' %} {{ name }}{% if value is not True %}="{{ value|stringformat:'s' }}"{% endif %}{% endif %}{% endfor %} id="{{widget.attrs.id}}_search_field">
<ul id="{{form.manufacturer.id_for_label}}-ac-ul" class="dropdown-menu">
</ul>
<input type="hidden" value="" name={{widget.name}}>
</div>