use await in hasServerError instead of old promise syntax

This commit is contained in:
Corentin Sechet 2023-04-17 16:00:25 +02:00
parent 07f81d27b7
commit d078755b15
1 changed files with 18 additions and 18 deletions

View File

@ -772,7 +772,7 @@ const LiveValidation = (function(){
/*
* Check validity of field by HTML attributes
* cf JS constaint validation API
* cf JS constraint validation API
* return first error found
*/
const hasAttrError = function (field) {
@ -792,28 +792,28 @@ const LiveValidation = (function(){
/*
* Check validity of field by request to server
*/
const hasServerError = function (name, field, form, url) {
return fetch( url+name, {
const hasServerError = async function (name, field, form, url) {
const response = await fetch( url+name, {
method: 'POST',
body: new FormData(form)
})
.then( (response) => response.json() )
.then( (json) => {
if (json.err !== 1) {
return
} else {
// XXX: if faut plutôt retourner json.msg qui contiendra le bon message
// d'erreur
let errorType
for (const key in json) {
if (json[key] === true) {
errorType = key
break
}
json = await response.json()
if (json.err !== 1) {
return
} else {
// XXX: if faut plutôt retourner json.msg qui contiendra le bon message
// d'erreur
let errorType
for (const key in json) {
if (json[key] === true) {
errorType = key
break
}
return errorType
}
})
return errorType
}
}
class FieldLiveValidation {