PluginProbe
Code Snippets / 3.2.1
Code Snippets v3.2.1
3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 3.0.1 All 64 releases
code-snippets / js / edit / validate.ts

validate.ts in Code Snippets 3.2.1, at js/edit/validate.ts

24 lines 796 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 export const handleFormSubmitValidation = () => {
2 const form = document.getElementById('snippet-form')
3 const editor = window.code_snippets_editor?.codemirror
4 const strings = window.code_snippets_edit_i18n
5 const snippetName = document.querySelector('input[name=snippet_name]') as HTMLInputElement
6
7 if (!form || !editor || !snippetName) {
8 return
9 }
10
11 form.addEventListener('submit', (event: SubmitEvent) => {
12 const missingTitle = '' === snippetName.value.trim()
13 const missingCode = '' === editor.getValue().trim()
14
15 const message = missingTitle ?
16 missingCode ? strings.missing_title_code : strings.missing_title :
17 missingCode ? strings.missing_code : ''
18
19 if (event?.submitter?.id.startsWith('save_snippet') && message && !confirm(message)) {
20 event.preventDefault()
21 }
22 })
23 }
24