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.
		
		
		
		
		
			
		
			
				
					
					
						
							37 lines
						
					
					
						
							718 B
						
					
					
				
			
		
		
	
	
							37 lines
						
					
					
						
							718 B
						
					
					
				export default class extends HTMLElement {
 | 
						|
  connectedCallback () {
 | 
						|
    this.form.addEventListener('submit', (e) => {
 | 
						|
      e.preventDefault()
 | 
						|
 | 
						|
      this.submit()
 | 
						|
    })
 | 
						|
 | 
						|
    if (this.dataset.onload === 'true') {
 | 
						|
      this.form.querySelector('button').click()
 | 
						|
    }
 | 
						|
  }
 | 
						|
 | 
						|
  submit () {
 | 
						|
    fetch(this.form.action, {
 | 
						|
      method: this.form.method,
 | 
						|
      body: new FormData(this.form)
 | 
						|
    }).then(async (resp) => {
 | 
						|
      if (!resp.ok) {
 | 
						|
        try {
 | 
						|
          const data = JSON.parse(await resp.text())
 | 
						|
 | 
						|
          if (data.error) {
 | 
						|
            alert(data.error)
 | 
						|
          }
 | 
						|
        } catch (err) {
 | 
						|
          console.error(err)
 | 
						|
        }
 | 
						|
      }
 | 
						|
    })
 | 
						|
  }
 | 
						|
 | 
						|
  get form () {
 | 
						|
    return this.querySelector('form')
 | 
						|
  }
 | 
						|
}
 |