Hubspot form embed onFormReady function from hbspt.forms.create TypeError: e.serializeArray is not a function

42 views Asked by At

I am trying to serialize an array for inputs in the Hubspot form to add or change cookies, but I keep getting the error onFormReady function from hbspt.forms.create TypeError: e.serializeArray is not a function and I don't know what to do. I am trying to not use jQuery, what can I use to replace it?

<script>
  hbspt.forms.create({
  region: "",
  portalId: "",
  formId: "",
  redirectUrl: "/thank-you/",
  onFormReady: function(e){
    e.serializeArray().map(x=>{
      let cookie_val = Cookies.get(x.name)
      if (cookie_val && cookie_val != ''){
        e.find('input[name="'+x.name+'"]').val(cookie_val).change();
      }
    })
  }
});
</script>
1

There are 1 answers

5
Alex Borodin On

According to docs, onFormReady returns form object. It is not an array, so you can try to serialize inputs:

  onFormReady: function(e){
    e.find('input').serializeArray().map(x=>{
      let cookie_val = Cookies.get(x.name)
      if (cookie_val && cookie_val != ''){
        e.find('input[name="'+x.name+'"]').val(cookie_val).change();
      }
    })
  }