Skip to content

Commit

Permalink
Merge pull request #5561 from Laravel-Backpack/navigate-to-tab-when-a…
Browse files Browse the repository at this point in the history
…uto-focusing

navigate to tab when auto-focusing
  • Loading branch information
pxpm authored Jul 15, 2024
2 parents ec78467 + 0c10045 commit d9274e7
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/resources/views/crud/form_content.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,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'));
Expand Down

0 comments on commit d9274e7

Please sign in to comment.