onFormSubmit fails to fire 1-2% of the time



We get roughly 500-1k form fills on our Hubspot forms every day and because of one of our integrations, we have to strip newline characters from the submitted form data.

in our hbspt.forms.create, we have an onFormSubmit function that looks something like this:

onFormSubmit: $form => {
        $form.find('input, textarea').each(() => {
            let el = $(this).get(0);

            $(this).val($(this).val().replace(/\n|\r/g, ' '));
            el.defaultValue = el.defaultValue.replace(/\n|\r/g, ' ');

We’re finding that roughly ~1-2% of the time consistently, this event is not firing before the form is submitting and our integration ends up not parsing the message body correctly. We added logging in and were able to determine that onFormSubmit was never being called. Our first thoughts were that it might be a browser specific issue, but on examination this seemed to be happening uniformly across all modern browsers/devices.

I don’t think we’re doing anything wrong here and all of the documentation claims that onFormSubmit is a blocking function, but if somebody could open our eyes here, that would be helpful.