From 0c1004562e2b8bc7ce6c42d3e814d6c9f130598e Mon Sep 17 00:00:00 2001 From: pxpm Date: Sat, 13 Jul 2024 22:21:14 +0100 Subject: [PATCH] navigate to tab when auto-focusing --- src/resources/views/crud/form_content.blade.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/resources/views/crud/form_content.blade.php b/src/resources/views/crud/form_content.blade.php index 4127294324..d92fbc6782 100644 --- a/src/resources/views/crud/form_content.blade.php +++ b/src/resources/views/crud/form_content.blade.php @@ -143,16 +143,23 @@ function preventUnload(event) { @if( $crud->getAutoFocusOnFirstField() ) @php $focusField = Arr::first($fields, function($field) { - return isset($field['auto_focus']) && $field['auto_focus'] == true; + return isset($field['auto_focus']) && $field['auto_focus'] === true; }); @endphp - let focusField; + let focusField, focusFieldTab; @if ($focusField) @php $focusFieldName = isset($focusField['value']) && is_iterable($focusField['value']) ? $focusField['name'] . '[]' : $focusField['name']; + $focusFieldTab = $focusField['tab'] ?? null; @endphp + focusFieldTab = '{{ Str::slug($focusFieldTab) }}'; + + // if focus is not 'null' navigate to that tab before focusing. + if(focusFieldTab !== 'null'){ + $('#form_tabs a[tab_name="'+focusFieldTab+'"]').tab('show'); + } focusField = $('[name="{{ $focusFieldName }}"]').eq(0); @else focusField = getFirstFocusableField($('form'));