Cannot read property 'target' of undefined from current.js

forms

#1

I am posting this issue after searching through all the threads of form submissions.

My scenario is, Our HubSpot form is hidden on the page and We are showing a custom form to the users. Users fill the custom form and we then put all the user submitted values to hidden HubSpot form and submit the form via the trigger. It was working perfectly until a couple of months ago but things got changed at HubSpot end and We are stuck :frowning:

Error appear on trigger is https://d.pr/uRoV6v

looking forward


Cannot read property 'target' of undefined from v2.js
Hubspot form: programmatically set field value via jQuery
#2

I found something very strange.

When I apply .change() on email field. It triggers this error, otherwise on all the other fields .change() works.

$("#hubspot-form form input[name='email']").val('myemail@test.com').change();


#3

Hi @Muhammad_Adnan,

Is this currently working? Embedded forms have some frontend validation for the email field, which might be triggered when you update the email field with the value from your external form.

I also wanted to recommend a simpler method; you can submit to the HubSpot Forms API using the new AJAX endpoint instead of embedding/hiding a form on the page:


#4

Hey @Derek_Gervais

Yea I think the new AJAX method is much better way but I was just getting curious that why It is only happening with the email field. I am even applying .change() after updating the email field form my form.


#5

What can be the work around for email validation?

$("#hubspot-form form input[type='email']").val(obj.email).change();


#6

Hi @Muhammad_Adnan,

I'm not able to reproduce this with a form in my own portal, so it might be something specific to your setup. Can you send me a link to the page you're working on?


#7

Really?

Can you share your form with me?
here is my page link https://distility.com/branding-readiness-assessment/


#8

Hi @Muhammad_Adnan,

Sure thing; here's a super simple test page I set up in my portal:
https://www.over-understanding.info/example-email-field-population

I checked out your page, and from what I can see the form isn't an embedded HubSpot form. I generally populate the email field with code like this:

$("input[name='email']").val("test@test.com").change();

The code you included above is different, but theoretically should work. I think the issue is that your selector includes HubSpot form markup that doesn't appear in the DOM. Trying the following in the console worked for me:

$("input[type='email']").val("test@test.com").change();

#9

I got it solved, The real problem was I was using
js.hsforms.net/forms/current.js

whereas It should be

js.hsforms.net/forms/v2.js

So, the problem solved for me.


#10

Hello @Derek_Gervais, @Muhammad_Adnan

I have same issue "Cannot read property ‘target’ of undefined from v2.js". i am using hubspot form module and fill data from external html form.

There is issue with email field only.


Cannot read property 'target' of undefined from v2.js
#11

We are facing the same problem and are using the v2.js... Any solutions so far

Code invoked ...
jQuery('input[name="email"]').val(hs_email).change();

The bold part seems to be the problem ... ( the email object has the correct email address value ).

The error returned is ...
v2.js:formatted:14112 Uncaught TypeError: Cannot read property 'target' of undefined


#12

I'm also experiencing the same problem using Hubspot's recommended method of introducing a change event
hbspt.forms.create({
portalId: "xxxxxxx",
formId: "xxxxxxx-xxxxxxx-xxxxxx-xxxxxx",
onFormReady($form) {
$('input[name="email"]').val(emailAddress).change();
}
});
And return the error
http://js.hsforms.net/forms/v2.js: Uncaught TypeError: Cannot read property 'target' of undefined

Some HS developer support would be appreciated, as many people seem to be experiencing this same issue.


#13

@TIDEV, @sreece - reached out internally to the forms team to get clarification on this error. Will update when I have more info


#15

Any progress on this ... and guideline on when the fix will be in place


#16

Hey @TIDEV, still waiting on the forms team for clarification on if this is a bug or not. For what it's worth, I was able to get the console error to clear if I provided a callback like this:

onFormReady: jQuery('input[name="email"]').val('singhj@theinstitutes.org').change(function(){
    console.log(this.val + " changed");
});

I'll update you when I get more info


#18

Appreciate your help following up, I understand you were able to get the console error to clear, but as you mentioned it does not solve the purpose of making the callback back to Hubspot to take action on the email address change (which you are following up with Hubspot forms team) ….

If you see the API documentation https://developers.hubspot.com/docs/methods/forms/advanced_form_options , It clearly states in red note: If you are using jQuery to manipulate the values of form inputs (i.e. using val() or prop()), you must trigger a change event using change() or trigger('change') for the change to properly register.

The purpose behind this was to trigger the callback function to return resubscribeMessage “Looks like you've opted out of email communication. Click here to get an email and opt back in.”

The capability did work for a year, so hopefully it’s treated with priority.


#19

Hi @TIDEV, yep - the team that owns forms is working on it currently. Appreciate your patience.


#20

Hi @TIDEV et al., this issue should now be resolved. The forms team has addressed the issue and console errors should be cleared up.


#21

Thank you Connor_Barley , appreciate your help investing this issue and following through with it to have it fixed.

The fix helped resolve forms callback issue that we were facing.

Regards

  •      Jaski