Tangerine-Community / tangy-form

<tangy-form> is a web component for creating multipage forms. Other <tangy-*> input elements are included as well.
GNU General Public License v3.0
15 stars 3 forks source link

tangy-checkboxes-dynamic not fetching forms.json #272

Open chrisekelley opened 3 years ago

chrisekelley commented 3 years ago

In certain circumstances on an APK, the following code fails even if it has received the payload:

const request = new XMLHttpRequest();
    request.onreadystatechange = function () {
      if (this.readyState === 4 && this.status === 200) {

Even if readyState === 4, the status stays at 0, never reaching 200, but responseText is populated.

chrisekelley commented 3 years ago

Check the fetchLocal function in the code here: https://github.com/Tangerine-Community/Tangerine/commit/aca5b643586cd68cb497d8e5770ee5c183827efe#diff-654a2a2a2f2db514da7640fbeabb70f9527941294e1c14a28628cd188e440454

function fetchLocal(url) {
      return new Promise(function(resolve, reject) {
        var xhr = new XMLHttpRequest
        xhr.responseType = 'json';
        xhr.onload = function() {
          if (xhr.status < 200 || xhr.status >= 300) {
            if (xhr.status === 0) {
                if (Array.isArray(xhr.response)) {
                    resolve(xhr.response)
                } else {
                    reject({request: xhr});
                }
            } else {
              reject({request: xhr});
            }
          } else {
          resolve(xhr.response)
          }
        }
        xhr.open('GET', url)
        xhr.send(null)
      })
    }