The onFormReady function in hbspt.forms.create requires jQuery. It was not run


#1

I get the following error when I try to manipulate DOM loaded from Hubspot form.
The onFormReady function in hbspt.forms.create requires jQuery. It was not run.
This is the code I use to change input field value:
hbspt.forms.create({
portalId: 'XXXXXX',
formId: 'aa8b5b4a-62ac-461b-a387-XXXXXXXXXXX',
onFormReady($form, ctx){
$('#firstname-6ae5c91f-67cf-40e7-bc53').val('Brian').change();
}
});
Anyone has the same issue? :thinking:


#2
hbspt.forms.create({
portalId: 'XXXXXX',
formId: 'aa8b5b4a-62ac-461b-a387-XXXXXXXXXXX',
onFormReady: function($form, ctx){
$('#firstname-6ae5c91f-67cf-40e7-bc53').val('Brian').change();
}
});

#3

Still getting the same error:

The onFormReady function in hbspt.forms.create requires jQuery. It was not run.


#4

Hi @Payman_Ferdowsali,

This might be a basic question to start, but do you have jQuery included on the page in question? Is it loaded before the form script?


#5

@Payman_Ferdowsali

As @Derek_Gervais is saying, you might not have jQuery loaded on the page. But if you don't need or want jQuery on the page, the offending code is $('#firstname-6ae5c91f-67cf-40e7-bc53')... This is jQuery syntax.

If you replace it with:

document.getElementById("firstname-6ae5c91f-67cf-40e7-bc53").value = "Brian";

I am not sure what the change event is for, but that will set the value to "Brian"

Full code:

hbspt.forms.create({
	portalId: 'XXXXXX',
	formId: 'aa8b5b4a-62ac-461b-a387-XXXXXXXXXXX',
	onFormReady: function($form, ctx){
		document.getElementById("firstname-6ae5c91f-67cf-40e7-bc53").value = "Brian";
	}
});

#6

I tried nothing under the onFormReady callback function, no matter what it gives me the same error:
shell.js:9 The onFormReady function in hbspt.forms.create requires jQuery. It was not run.
If I remover the onFormReady callback, I don't get error! :thinking:


#7

Hi @Payman_Ferdowsali,

The onFormReady callback requires jQuery to function properly. Some other community users have found some workarounds you might find useful: