{% 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 #}
{{ help_text|default:field.help_text }}
{% endif %} {% if field.errors %}{{ field.errors.0 }}
{% endif %}{{ help_text }}
{% endif %} {% if error %}{{ error }}
{% endif %}