APIs & Integrations

Muhammad_Adnan
Member

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

SOLVE

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

0 Upvotes
1 Accepted solution
cbarley
Solution
HubSpot Alumni
HubSpot Alumni

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

SOLVE

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

View solution in original post

0 Upvotes
19 Replies 19
linehammer
Member

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

SOLVE

This error occurs in Chrome Browser when you read a property or call a method on an undefined object . Uncaught TypeError: Cannot read property of undefined error is probably easiest to understand from the perspective of undefined, since undefined is not considered an object type at all (but its own undefined type instead), and properties can only belong to objects within JavaScript. There are a few variations of this error depending on the property you are trying to access. Sometimes instead of undefined it will say null.

 

0 Upvotes
cbarley
Solution
HubSpot Alumni
HubSpot Alumni

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

SOLVE

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

0 Upvotes
TIDEV
Member

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

SOLVE

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
TIDEV
Member

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

SOLVE

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

0 Upvotes
cbarley
HubSpot Alumni
HubSpot Alumni

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

SOLVE

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

0 Upvotes
TIDEV
Member

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

SOLVE

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.

0 Upvotes
cbarley
HubSpot Alumni
HubSpot Alumni

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

SOLVE

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

0 Upvotes
sreece
Member

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

SOLVE

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.

0 Upvotes
cbarley
HubSpot Alumni
HubSpot Alumni

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

SOLVE

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

0 Upvotes
TIDEV
Member

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

SOLVE

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

0 Upvotes
developer_esb
Member

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

SOLVE

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.

0 Upvotes
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

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

SOLVE

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();
0 Upvotes
Muhammad_Adnan
Member

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

SOLVE

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.

Derek_Gervais
HubSpot Alumni
HubSpot Alumni

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

SOLVE

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?

Muhammad_Adnan
Member

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

SOLVE

Really?

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

0 Upvotes
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

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

SOLVE

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:

Muhammad_Adnan
Member

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

SOLVE

What can be the work around for email validation?

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

0 Upvotes
Muhammad_Adnan
Member

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

SOLVE

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.

0 Upvotes
Muhammad_Adnan
Member

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

SOLVE

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();

0 Upvotes