CMS Development

ringlead
Participant

HubSpot integration with custom javascript

We added custom javascript to our customers landing page.  When you type a company name in the company field, we provide a picklist of options.  When user selects a company from the picklist, our javascript changes value to the selected value, but HubSpot is changing the value back to the originally typed value.

 

Has anyone seen this?  If you can provide any suggestions or assistance we would appreciate it.

 

 

0 Upvotes
4 Replies 4
derekcavaliero
Top Contributor | Diamond Partner
Top Contributor | Diamond Partner

HubSpot integration with custom javascript

I've run into this before. Make sure that after you update the fields value via JavaScript - that you also explicitly trigger a "change" event. 

 

Screen Shot 2019-06-12 at 7.57.33 AM.png 

They don't really say "why" you need to do this - but I suspect it has something to do with the way the form is mounted via React and that without a "change" event - the "state" or "Single Source of Truth" object doesn't get properly updated and reverts to the state that was stored from the last change/render event.

 

Hopefully that helps!

Derek Cavaliero
Director of Engineering

WebMechanix
www.webmechanix.com
ringlead
Participant

HubSpot integration with custom javascript

Thanks Derek, this helped resolve the issue we were facing, but we have encountered another similar issue:


Our developers were able to set values using above solution and it worked. But we came across another issue where dropdowns/picklists are not updating.

 
Any way we can update those?
0 Upvotes
derekcavaliero
Top Contributor | Diamond Partner
Top Contributor | Diamond Partner

HubSpot integration with custom javascript

Thats strange - mind providing me a code example so I could see how you're prefilling those fields? I do remember some oddities - but seeing an example might help refresh my memory :D.

Derek Cavaliero
Director of Engineering

WebMechanix
www.webmechanix.com
0 Upvotes
ringlead
Participant

HubSpot integration with custom javascript

here are two ways we tried to set values:

1)
var selectElement = document.getElementById(<select_element_id>)
selectElement.selectedIndex = opt // index of option

2)
var selectElement = document.getElementById(<select_element_id>)
selectElement.value = value // actual value of selected option

0 Upvotes