Otp Input
One-time code input component.
Preview
Arguments
otp_input(name='code', digits=6, label='Verification code', event='verify_code')
Usage
views.py
python
from djust import LiveView
from djust.decorators import event_handler
from djust.components import OtpInput
class MyView(LiveView):
template_name = "my_template.html"
def mount(self, request, **kwargs):
self.component = OtpInput(name='code', digits=6, label='Verification code', event='verify_code')
@event_handler()
def verify_code(self, value=None, **kwargs):
pass # your app acts on 'verify_code'; no component state movesmy_template.html
django
{{ component }}Events this component sends to the view: verify_code.
Needs its script on the page: <script src="{% static 'djust_components/otp-input.js' %}"></script>. djust ships it; without it the markup renders but does not update in the browser.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| name | str | '' | form field name |
| digits | int | 6 | number of digit boxes |
| event | str — renames the event | '' | dj-change event name |
| label | str | '' | label text |
| custom_class | str | '' | — |
| **kwargs | — passed to `Component.__init__`: `id=` sets `component.id`, and any other keyword is kept as state | — | — |
Source & styles
| File | Path | Notes |
|---|---|---|
| module | djust.components.components.otp_input | Subclass it, or pass custom_class, to change how it renders. |
| css | djust_components/components.css | Defines 4 of this component's classes at line 525, 972, 973, 974. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |
| css | djust_theming/components.css | Defines 1 of this component's classes at line 1453. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |
| css | djust_theming/scaffold.css | Defines 1 of this component's classes at line 445. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |