text: 
  async function previewFile() {
      const preview = document.querySelector('img');
      const file = document.querySelector('input[type=file]').files[0];
      const reader = new FileReader();
  
      reader.addEventListener("load", function () {
        // convert image file to base64 string
          preview.src = reader.result;
      }, false);
      if (file) {
          reader.readAsDataURL(file);
      }
  }
  if (dogImage) {
      console.log ("file exists")
  } else {
      console.log("no file")
  }
  formElem.onsubmit = async (e) => {
      e.preventDefault();
      const id = window.location.toString().split('/')[
          window.location.toString().split('/').length - 1
      ];
      let response = await fetch(`/api/dogs/${id}`, {
          method: 'PUT',
          body: new FormData(formElem),
      });
  
  
      if (response.ok) {
          document.location.replace('/dashboard');
          } else {
          //alert("Please complete all fields to update your dog");
          }
  };
  
  // disables form submissions if there are invalid fields
  (function() {
      'use strict';
      window.addEventListener('load', function() {
        // Fetch all the forms we want to apply custom Bootstrap validation styles to
      var forms = document.getElementsByClassName('needs-validation');
      // Loop over them and prevent submission
      var validation = Array.prototype.filter.call(forms, function(form) {
      form.addEventListener('submit', function(event) {
          if (form.checkValidity() === false) {
          event.preventDefault();
          event.stopPropagation();
          }
          form.classList.add('was-validated');
      }, false);
      });
  }, false);
  })();