Skip to content

Commit

Permalink
fix this.httpMethod
Browse files Browse the repository at this point in the history
  • Loading branch information
srt32 committed May 24, 2024
1 parent 9dc10b4 commit fe7b0a2
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/auto-check-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,11 @@ function setLoadingState(event: Event) {

const src = autoCheckElement.src
const csrf = autoCheckElement.csrf
const httpMethod = autoCheckElement.httpMethod
const state = states.get(autoCheckElement)

// If some attributes are missing we want to exit early and make sure that the element is valid.
if (!src || (this.httpMethod === 'POST' && !csrf) || !state) {
if (!src || (httpMethod === 'POST' && !csrf) || !state) {
return
}

Expand Down Expand Up @@ -242,9 +243,10 @@ async function check(autoCheckElement: AutoCheckElement) {
const src = autoCheckElement.src
const csrf = autoCheckElement.csrf
const state = states.get(autoCheckElement)
const httpMethod = autoCheckElement.httpMethod

// If some attributes are missing we want to exit early and make sure that the element is valid.
if (!src || (this.httpMethod === 'POST' && !csrf) || !state) {
if (!src || (httpMethod === 'POST' && !csrf) || !state) {
if (autoCheckElement.required) {
input.setCustomValidity('')
}
Expand All @@ -259,7 +261,7 @@ async function check(autoCheckElement: AutoCheckElement) {
}

const body = new FormData()
if (this.httpMethod === 'POST') {
if (httpMethod === 'POST') {
body.append(csrfField, csrf)
body.append('value', input.value)
} else {
Expand All @@ -281,7 +283,7 @@ async function check(autoCheckElement: AutoCheckElement) {
const response = await fetchWithNetworkEvents(autoCheckElement, src, {
credentials: 'same-origin',
signal: state.controller.signal,
method: this.httpMethod,
method: httpMethod,
body,
})
if (response.ok) {
Expand Down

0 comments on commit fe7b0a2

Please sign in to comment.