{% comment %} Input Component - Unified Django Template Version of shadcn/ui Input A versatile input component that supports both Django form fields and standalone inputs. Compatible with HTMX and Alpine.js for dynamic behavior. Usage Examples: Standalone input: {% include 'components/ui/input.html' with type='text' name='email' placeholder='Enter email' %} With Django form field: {% include 'components/ui/input.html' with field=form.email label='Email Address' %} With HTMX validation: {% include 'components/ui/input.html' with name='username' hx_post='/validate' hx_trigger='blur' %} With Alpine.js binding: {% include 'components/ui/input.html' with name='search' x_model='query' %} Textarea mode: {% include 'components/ui/input.html' with type='textarea' name='message' rows='4' %} Parameters: Standalone Mode: - type: Input type (text, email, password, number, etc.) or 'textarea' (default: 'text') - name: Input name attribute - id: Input ID (auto-generated from name if not provided) - placeholder: Placeholder text - value: Initial value - label: Label text - help_text: Help text displayed below the input - error: Error message to display - required: Boolean for required field - disabled: Boolean to disable the input - readonly: Boolean for readonly input - autocomplete: Autocomplete attribute value - rows: Number of rows for textarea - class: Additional CSS classes for the input Django Form Field Mode: - field: Django form field object - label: Override field label - placeholder: Override field placeholder - help_text: Override field help text HTMX Attributes: - hx_get, hx_post, hx_target, hx_swap, hx_trigger, hx_include: HTMX attributes Alpine.js Attributes: - x_model: Two-way binding - x_on: Event handlers (as string, e.g., "@input=...") - x_data: Alpine data Other: - attrs: Additional HTML attributes as string - aria_describedby: ID of element describing this input - aria_invalid: Boolean for invalid state {% endcomment %} {% load widget_tweaks %} {% if field %} {# Django Form Field Mode #}
{% if label or field.label %} {% endif %} {% render_field field class+="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50" placeholder=placeholder|default:field.label aria-describedby=field.id_for_label|add:"-description" aria-invalid=field.errors|yesno:"true,false" %} {% if help_text or field.help_text %}

{{ help_text|default:field.help_text }}

{% endif %} {% if field.errors %} {% endif %}
{% else %} {# Standalone Mode #} {% with input_id=id|default:name %}
{% if label %} {% endif %} {% if type == 'textarea' %} {% else %} {% endif %} {% if help_text %}

{{ help_text }}

{% endif %} {% if error %} {% endif %}
{% endwith %} {% endif %}