Put the cursor in the first code box when the Turn on MFA window opens or reopens after a wrong code, and on the portal two-step setup opened at its section, without scrolling the QR code away

This commit is contained in:
johnnyq
2026-11-20 19:10:30 -05:00
parent 9dfa6016ae
commit 93baf11544
3 changed files with 32 additions and 3 deletions

View File

@@ -423,7 +423,7 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u
- Starter content: `starterPackRecords()`, `starterPackHere()`, `starterPackUsed()`, `starterContentUnused()` and `starterClearUnused()` in `admin/post/starter_content_model.php`, `clear_starter_unused` in `admin/post/starter_content.php` (rechecked on post, with an Undo of the archive) and `admin/modals/starter_content/starter_clear.php`. A tag counts as used by any table with a `tag_id` or `*_tag_id` column (read from information_schema) or a seat count, a project template by its tickets' history line, and a category by `categoryUsage()` plus ticket templates, settings, RMM alerts, AI triage and child categories. `starterPickHtml()` takes `$open`; `js/starter_content.js` counts `data-starter-format="clear"` and sets up a pack in a window as it opens.
- Tab rows: `js/tab_fold.js` (loaded by `includes/footer.php`) folds the tabs that don't fit into a More dropdown, from the end, never the `.active` one - in `.nav.itflow-asset-tabs` (or a `.nav` inside an `.itflow-asset-tabs` card header), `.nav.itflow-asset-pills`, `.nav.itflow-asset-form-tabs` and any `.nav.itflow-tabs-foldable` (added to the kinds in Admin > Categories and Tags and to the mail settings tabs). A tab is a `.nav-link` of the row or the `.nav-item` around one; rows in a window are set up on `shown.bs.modal`, and a row laid out as a column, or not on screen yet, is left as it is. Folded tabs stay in place with `.itflow-tab-folded`, so Bootstrap's tabs and page scripts keep working on them; More is a `.nav-link.dropdown-toggle` (left out by Bootstrap's tabs and by `agent/js/tickets_live.js`), and its items are built on `show.bs.dropdown` - a link for a tab with an href, otherwise a button that clicks the tab. The row gets `.itflow-tabs-fold` (one line, overflow visible, min-width 0, its tabs `nowrap`), and fits again on resize, font load and any change to its tabs (a MutationObserver - counts updated in place, the open tab changing).
- Link picker: `functions/link_picker.php` (`linkPickerButton()`, `linkPickerSource()`, `linkPickerOptions()`, `linkPickerSave()`, `LINK_PICKER_OWN` for the links that aren't `LINK_RELATIONS` pairs), `js/link_picker.js`, and `agent/ajax.php` `link_picker` (GET: the options, linked ones selected) and `link_picker_save` (POST `add[]` and `remove[]`; `flash=1` keeps the message for the page it reloads). It opens the select picker on a hidden multiple `<select>`: in `js/itflow_select.js` a picker's `.anchor` puts the panel under that element, and closing fires `itflow:close`. With no `to`, the options are grouped by kind and their values are `type:id`. The link windows (`agent/modals/link/link.php` and its one-pair wrappers, `contact_link_asset.php`, `contact_link_credential.php`, `asset_link_credential.php`, `project_link_ticket.php`, `service_link_ticket.php`, `ticket_link_service.php`, `ticket_link.php`) and the handlers only they posted to (`link_items`, `link_tickets`, `link_service_tickets`, `link_ticket_services`, `link_ticket_to_project`, `link_contact_to_asset`, `link_contact_to_credential`, `link_asset_to_credential`) are gone; the unlink handlers stay. `js/ajax_modal.js` keeps a window's URL in `data-modal-url`, so a quick look loads again in place after a change, and `js/tab_fold.js` exposes `window.itflowTabFold()`.
- Code boxes: `otpCodeInput()` in `functions/user.php` draws a 6-digit code field (options: id, label, class, autofocus, submit, invalid) and `js/otp_input.js` (loaded by `includes/footer.php`, `client/includes/footer.php`, `login.php`, `agent/user/mfa_enforcement.php` and `guest/share.php`) lays the one see-through input over six `.itflow-otp-slot` boxes - typing, paste and autofill go to the input, the boxes only show it. Non-digits are stripped (a pasted "123 456" fills them all), the caret stays at the end, a value set from script redraws them (the input's own `value` property), and the `is-invalid` class on the input turns them red until the next digit. `data-otp-submit` sends the form with `requestSubmit()` and its first submit button once the sixth digit is in; `window.itflowOtp(input)` does one added later. `login.php` (agent and client steps), `agent/user/includes/mfa_setup.php`, `client/profile.php` and `guest/share.php` use it; `.itflow-mfa-code` is gone.
- Code boxes: `otpCodeInput()` in `functions/user.php` draws a 6-digit code field (options: id, label, class, autofocus, submit, invalid) and `js/otp_input.js` (loaded by `includes/footer.php`, `client/includes/footer.php`, `login.php`, `agent/user/mfa_enforcement.php` and `guest/share.php`) lays the one see-through input over six `.itflow-otp-slot` boxes - typing, paste and autofill go to the input, the boxes only show it. Non-digits are stripped (a pasted "123 456" fills them all), the caret stays at the end, a value set from script redraws them (the input's own `value` property), and the `is-invalid` class on the input turns them red until the next digit. `data-otp-submit` sends the form with `requestSubmit()` and its first submit button once the sixth digit is in; `window.itflowOtp(input)` does one added later. One with `autofocus` is focused (without scrolling) when its modal opens (`shown.bs.modal`), and on load when the browser skipped it - a page opened at a `#fragment`. `login.php` (agent and client steps), `agent/user/includes/mfa_setup.php`, `client/profile.php` and `guest/share.php` use it; `.itflow-mfa-code` is gone.
## [26.11.8]

View File

@@ -32,4 +32,4 @@ $mfa_secret_grouped = trim(chunk_split($mfa_secret, 4, ' '));
<ol class="itflow-mfa-steps small text-start ps-3 mb-2" start="3">
<li>Enter the 6-digit code it shows:</li>
</ol>
<?= otpCodeInput('verify_code', ['submit' => true]) ?>
<?= otpCodeInput('verify_code', ['submit' => true, 'autofocus' => true]) ?>

View File

@@ -11,7 +11,9 @@
*
* Fields on the page are done on load; window.itflowOtp(input) does one added
* later. Setting the field's value from script redraws the boxes, and the
* is-invalid class on it turns them red until the next digit.
* is-invalid class on it turns them red until the next digit. One with
* autofocus gets the focus when its window opens, and on load where the
* browser skipped it (a page opened at a #section), without scrolling to it.
*/
(function () {
'use strict';
@@ -142,10 +144,37 @@
new MutationObserver(render).observe(input, { attributes: true, attributeFilter: ['class'] });
render();
if (input.hasAttribute('autofocus')) {
// Once more after load - going to a #section takes the focus away again
focusIfIdle(input);
if (document.readyState !== 'complete') {
window.addEventListener('load', function () {
setTimeout(function () {
focusIfIdle(input);
});
}, { once: true });
}
}
}
// When nothing else has the focus - not taking it from a field already being typed in
function focusIfIdle(input) {
if (!document.activeElement || document.activeElement === document.body) {
input.focus({ preventScroll: true });
}
}
window.itflowOtp = init;
// A window with a code to type - straight into the first box
document.addEventListener('shown.bs.modal', function (e) {
const input = e.target.querySelector('input[data-otp][autofocus]');
if (input) {
input.focus({ preventScroll: true });
}
});
function initAll() {
document.querySelectorAll('input[data-otp]').forEach(init);
}