Skip to content

Commit

Permalink
navigate to tab when auto-focusing
Browse files Browse the repository at this point in the history
  • Loading branch information
pxpm committed Jul 13, 2024
1 parent facb579 commit 0c10045
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 @@ -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'));
Expand Down

0 comments on commit 0c10045

Please sign in to comment.