Validation issue in custom installation page

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)
        }
      )
    }
  })
}

Hi @Vvikas
you need to return the value in validate method, otherwise, it throws an error,

eg:

function validate () {
  return validateHpApiKey($('#hpApiKey').val()) // this should either return true/false or promise to return true/false
}

hope it helps :slight_smile:

Thanks

Ahh, thank you it worked! I was under impression that I could return only boolean from validate() method.

1 Like

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.