Hello all,
I am building a custom installation page and experiencing issue with the validate()
method in iparams.html
.
validate()
method is always reporting validation error in the form irrespective of returning true/false
. Below is my code snippet:
validate() method in iparams.html
function validate () {
validateHpApiKey($('#hpApiKey').val()).then(data => {
console.log(data)
return data
})
}
validateHpApiKey() method in iparams.js
function validateHpApiKey (hpApiKey) {
return new Promise(resolve => {
hpApiKey = hpApiKey.trim()
if (!hpApiKey) {
showValidationMessage('hpApiKey', 'This field is required!')
resolve(false)
} else {
const options = {
body: JSON.stringify({
param: hpApiKey,
}),
}
client.request.post(`${API_DOMAIN}/api_key/true`, options).then(
function (data) {
// Upon success, just resolve
console.log(data)
resolve(true)
},
function (error) {
// Upon failure - send an appropriate validation error message
console.log(error)
showValidationMessage('hpApiKey', 'This API Key does not exist. Please enter the right one')
resolve(false)
}
)
}
})
}