add lint js
This commit is contained in:
@@ -1,14 +1,27 @@
|
||||
import {AxiosError} from "axios"
|
||||
|
||||
export function displayFormErrors(error: any, form: HTMLElement|null = null) {
|
||||
export function displayFormErrors(error: AxiosError, form: HTMLElement|null = null) {
|
||||
if (error.response && error.response.status === 422) {
|
||||
let errors = error.response.data.errors
|
||||
// @ts-expect-error test axios error
|
||||
const errors = error.response.data.errors
|
||||
const formBase = (form) ? form : document.body
|
||||
Object.keys(errors).forEach(key => {
|
||||
displayError(key, errors[key], formBase)
|
||||
Object.entries(errors).forEach(([key, value]) => {
|
||||
displayError(key, value, formBase)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export interface ValidationErrors {
|
||||
response: {
|
||||
status: number,
|
||||
data: {
|
||||
errors: object
|
||||
message?: string,
|
||||
}
|
||||
},
|
||||
message?: string,
|
||||
}
|
||||
|
||||
export function displayError(key: string, message: string, form: HTMLElement|null = null) {
|
||||
const formBase = (form) ? form : document
|
||||
const input = formBase.querySelector(`input[name="${key}"], select[name="${key}"], textarea[name="${key}"]`)
|
||||
|
||||
Reference in New Issue
Block a user