Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions assets/js/odw-admin-fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,30 @@
observer.observe( document.body, { childList: true, subtree: true } );
}

// -------------------------------------------------------------------------
// Auto-show distribution fields by clicking "Add Entry" on load
// -------------------------------------------------------------------------
function autoShowDistributionFields() {
// Find the distributions complex field container
var distributionsContainer = document.querySelector( '[data-carbon-field="odw_distributions"]' );
if ( ! distributionsContainer ) {
return;
}

// Check if there are any existing entries (groups)
var existingGroups = distributionsContainer.querySelectorAll( '.cf-complex__group' );
if ( existingGroups.length > 0 ) {
// Entries already exist, no need to auto-add
return;
}

// No entries exist, click "Add Entry" to show empty form
var addButton = distributionsContainer.querySelector( '.cf-complex__actions button' );
if ( addButton ) {
addButton.click();
}
}

// -------------------------------------------------------------------------
// Boot on DOMContentLoaded
// -------------------------------------------------------------------------
Expand All @@ -227,6 +251,9 @@
initCessdaAutosuggest();
initFileSizeWidgets();
observeNewGroups();

// Auto-show distribution fields if no entries exist
setTimeout( autoShowDistributionFields, 500 );
} );

} )();
1 change: 0 additions & 1 deletion includes/class-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ private static function register_required_fields(): void {
array(
Field::make( 'complex', 'odw_distributions', __( 'Wo können die Daten heruntergeladen werden?', 'open-data-wizard' ) )
->set_min( 1 )
->set_initial_rows( 1 )
->set_collapsed( false )
->add_fields(
array(
Expand Down
Loading