Skip to content

Commit 95d939d

Browse files
authored
Merge pull request #54 from eroluysal/main
added 'csrf-field' optional attribute.
2 parents 2310898 + 6827b65 commit 95d939d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ export default class AutoCheckElement extends HTMLElement {
8686
this.removeAttribute('required')
8787
}
8888
}
89+
90+
get csrfField(): string {
91+
return this.getAttribute('csrf-field') || 'authenticity_token'
92+
}
93+
94+
set csrfField(value: string) {
95+
this.setAttribute('csrf-field', value)
96+
}
8997
}
9098

9199
function setLoadingState(event: Event) {
@@ -151,6 +159,7 @@ async function check(autoCheckElement: AutoCheckElement) {
151159
return
152160
}
153161

162+
const csrfField = autoCheckElement.csrfField
154163
const src = autoCheckElement.src
155164
const csrf = autoCheckElement.csrf
156165
const state = states.get(autoCheckElement)
@@ -171,7 +180,7 @@ async function check(autoCheckElement: AutoCheckElement) {
171180
}
172181

173182
const body = new FormData()
174-
body.append('authenticity_token', csrf)
183+
body.append(csrfField, csrf)
175184
body.append('value', input.value)
176185

177186
input.dispatchEvent(

0 commit comments

Comments
 (0)