mirror of https://github.com/docusealco/docuseal
				
				
				
			
			You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							46 lines
						
					
					
						
							929 B
						
					
					
				
			
		
		
	
	
							46 lines
						
					
					
						
							929 B
						
					
					
				| import autocomplete from 'autocompleter'
 | |
| 
 | |
| export default class extends HTMLElement {
 | |
|   connectedCallback () {
 | |
|     autocomplete({
 | |
|       input: this.input,
 | |
|       preventSubmit: this.dataset.submitOnSelect === 'true' ? 0 : 1,
 | |
|       minLength: 0,
 | |
|       showOnFocus: true,
 | |
|       onSelect: this.onSelect,
 | |
|       render: this.render,
 | |
|       fetch: this.fetch
 | |
|     })
 | |
|   }
 | |
| 
 | |
|   onSelect = (item) => {
 | |
|     this.input.value = item.name
 | |
|   }
 | |
| 
 | |
|   fetch = (text, resolve) => {
 | |
|     const queryParams = new URLSearchParams({ q: text })
 | |
| 
 | |
|     fetch('/template_folders_autocomplete?' + queryParams).then(async (resp) => {
 | |
|       const items = await resp.json()
 | |
| 
 | |
|       resolve(items)
 | |
|     }).catch(() => {
 | |
|       resolve([])
 | |
|     })
 | |
|   }
 | |
| 
 | |
|   render = (item) => {
 | |
|     const div = document.createElement('div')
 | |
| 
 | |
|     div.setAttribute('dir', 'auto')
 | |
| 
 | |
|     div.textContent = item.name
 | |
| 
 | |
|     return div
 | |
|   }
 | |
| 
 | |
|   get input () {
 | |
|     return this.querySelector('input')
 | |
|   }
 | |
| }
 |