diff --git a/assets/js/odw-admin-fields.js b/assets/js/odw-admin-fields.js index bb68bcc..8809c36 100644 --- a/assets/js/odw-admin-fields.js +++ b/assets/js/odw-admin-fields.js @@ -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 // ------------------------------------------------------------------------- @@ -227,6 +251,9 @@ initCessdaAutosuggest(); initFileSizeWidgets(); observeNewGroups(); + + // Auto-show distribution fields if no entries exist + setTimeout( autoShowDistributionFields, 500 ); } ); } )(); diff --git a/includes/class-fields.php b/includes/class-fields.php index c8c989c..28c0d2a 100644 --- a/includes/class-fields.php +++ b/includes/class-fields.php @@ -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(