APIs & Integrations

Not applicable

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

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:

0 Upvotes
7 Replies 7
SKhan74
Member

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

Try it. 
hbspt.forms.create({

portalId: 'XXXXXX',
formId: 'aa8b5b4a-62ac-461b-a387-XXXXXXXXXXX',

onFormReady: function ($form) {
 $form.find('input[name="firstname"]').val('Brian').change();
  }

});

0 Upvotes
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

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

Hi @Payman_Ferdowsali,

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

salty_stephen
Contributor | Elite Partner
Contributor | Elite Partner

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

@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";
	}
});
Not applicable

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

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:

0 Upvotes
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

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

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?

0 Upvotes
jayjiang
Member

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

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

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

Still getting the same error:

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

0 Upvotes