Skip to content

Commit

Permalink
Merge pull request #54 from eroluysal/main
Browse files Browse the repository at this point in the history
added 'csrf-field' optional attribute.
  • Loading branch information
koddsson authored Aug 4, 2021
2 parents 2310898 + 6827b65 commit 95d939d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ export default class AutoCheckElement extends HTMLElement {
this.removeAttribute('required')
}
}

get csrfField(): string {
return this.getAttribute('csrf-field') || 'authenticity_token'
}

set csrfField(value: string) {
this.setAttribute('csrf-field', value)
}
}

function setLoadingState(event: Event) {
Expand Down Expand Up @@ -151,6 +159,7 @@ async function check(autoCheckElement: AutoCheckElement) {
return
}

const csrfField = autoCheckElement.csrfField
const src = autoCheckElement.src
const csrf = autoCheckElement.csrf
const state = states.get(autoCheckElement)
Expand All @@ -171,7 +180,7 @@ async function check(autoCheckElement: AutoCheckElement) {
}

const body = new FormData()
body.append('authenticity_token', csrf)
body.append(csrfField, csrf)
body.append('value', input.value)

input.dispatchEvent(
Expand Down

0 comments on commit 95d939d

Please sign in to comment.