use await in hasServerError instead of old promise syntax
This commit is contained in:
parent
07f81d27b7
commit
d078755b15
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue