/** * JavaScript code for the "Import" screen. * * @package TablePress * @subpackage Views JavaScript * @author Tobias Bäthge * @since 1.0.0 */ /* globals jSuites */ /** * WordPress dependencies. */ import { __, _n, sprintf } from '@wordpress/i18n'; /** * Internal dependencies. */ import { $ } from './_common-functions'; const data = { source: '', type: '', }; const $import_form = $( '#tablepress_import-import-form' ); const $tables_import_file_upload_field = $( '#tables-import-file-upload' ); const $tables_import_file_upload_field_dropzone = $( '#tables-import-file-upload-dropzone' ); const $tables_import_server_field = $( '#tables-import-server' ); // The input field only exists for admins! const $import_existing_table_dropdown = $( '#tables-import-existing-table' ); /** * Progressively enhance the "Table to replace or append to" HTML select field with live-search and auto-complete. * * @since 2.0.0 */ jSuites.dropdown( $import_existing_table_dropdown, { autocomplete: true, placeholder: $import_existing_table_dropdown.options[0].textContent, } ); /** * Set state of visible form elements depending on selected options. * * @since 2.0.0 */ $import_form.addEventListener( 'change', () => { data.source = document.querySelector( '#row-import-source input:checked' ).value; data.type = document.querySelector( '#row-import-type input:checked' ).value; // Don't show validation :invalid CSS pseudo-selector highlighting, but only when the user wants to submit the form. $import_form.classList.add( 'no-validation-highlighting' ); // Reset validation messages after a change to a form field was made. $tables_import_server_field?.setCustomValidity( '' ); // The input field only exists for admins! $import_existing_table_dropdown.previousElementSibling.querySelector( '.jdropdown-header' ).setCustomValidity( '' ); // Use the jSuites dropdown input field, as the actual is hidden. } } } );