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
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.
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:
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.
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.
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:
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?
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:
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.