Skip to content
Devix Open Source

Type in the middle

Put the caret anywhere in a half-filled field and keep typing. The counter is the number of times the caret ended up somewhere other than where you left it.

Live preview
<div class="demo demo--wide">
  <label class="demo-hint" for="cnic">A Pakistani CNIC</label>
  <form id="form" action="#" onsubmit="return false">
    <input class="demo-input" id="cnic" name="cnic" placeholder="42101-1234567-1" inputmode="numeric">
  </form>

  <p class="demo-hint">Type a few digits, click into the middle, and carry on. Backspace over a
    dash. Paste <code>42101-1234567-1</code> over the lot.</p>

  <dl class="demo-kv" id="out"></dl>

  <div class="demo-row">
    <button class="demo-btn demo-btn--ghost" id="paste">Paste a formatted one</button>
    <button class="demo-btn demo-btn--ghost" id="clear">Clear</button>
  </div>

  <p class="demo-hint">The second row is what an ordinary form submit would send — no JavaScript
    of yours involved, because the widget moved the field's <code>name</code> onto a hidden input.</p>
</div>