HEX
Server: Apache
System: Linux elegant-goodall 5.15.0-107-generic #117-Ubuntu SMP Fri Apr 26 12:26:49 UTC 2024 x86_64
User: allende-losmares.com_h71qfkqzx8k (10002)
PHP: 8.0.30
Disabled: opcache_get_status
Upload Files
File: /var/www/vhosts/allende-losmares.com/httpdocs/wp-content/plugins/code-snippets/js/edit/validate.ts
export const handleFormSubmitValidation = () => {
	const form = document.getElementById('snippet-form')
	const editor = window.code_snippets_editor?.codemirror
	const strings = window.code_snippets_edit_i18n
	const snippetName = document.querySelector('input[name=snippet_name]') as HTMLInputElement

	if (!form || !editor || !snippetName) {
		return
	}

	form.addEventListener('submit', (event: SubmitEvent) => {
		const missingTitle = '' === snippetName.value.trim()
		const missingCode = '' === editor.getValue().trim()

		const message = missingTitle ?
			missingCode ? strings.missing_title_code : strings.missing_title :
			missingCode ? strings.missing_code : ''

		if (event?.submitter?.id.startsWith('save_snippet') && message && !confirm(message)) {
			event.preventDefault()
		}
	})
}