Move labels below the inputs in Embedded Form

I’m trying to manipulate the DOM with jquery in the form embed code.

<script>
 hbspt.forms.create({
 portalId: "xxxxx",
 formId: "xxxx",
 cssClass: '',
 cssRequired: 'form__field required',
 errorClass: 'form__field',
 errorMessageClass: 'error',
 submitButtonClass: 'submitBTN',
 onFormReady: function ($form) {
 $('form').wrapInner('<div class="form-row form_block"></div>')
 $('.hs-form-field').addClass('form-group col-md-12');
 $('input').addClass('form__field');
 $('label').addClass('form__label');
 $(".input input").each(function () {
 var e = $(this);
 e.parent().parent().find('label').insertAfter(e);
 })
 }
 });
 </script>

However, I’m running into an issue.

When a field isn’t valid . Then trying to go back into the field to edit, i get the below JS error

v2.js:4 Uncaught Error: Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.
 at r (v2.js:4)
 at Object.processUpdates (v2.js:1)
 at Object.dangerouslyProcessChildrenUpdates [as processChildrenUpdates] (v2.js:2)
 at s (v2.js:3)
 at a.updateChildren (v2.js:3)
 at a._updateDOMChildren (v2.js:2)
 at a.updateComponent (v2.js:2)
 at a.receiveComponent (v2.js:2)
 at Object.receiveComponent (v2.js:3)
 at u._updateRenderedComponent (v2.js:2)

When I remove the label insertAfter() script those go away

Hey @rjsnyderdesign,

Are you able to get the full error message on the non-minified dev environment?

For now, my current hypothesis is that either the label or var e doesn’t exist which is why it might be throwing a invalid error. Hence, your team should probably explore the option of using a if/else check to see if the element exist. i.e. Jquery insertAfter only once if element exist - Stack Overflow

Hi @WendyGoh

I’m not sure show to get the non minified version. That error is coming from the hubspot script:

<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2.js"></script>

We’re not getting an error when trying to move the label around. It moves and works well. But, it has something to do with validation of the form.

Thanks for your help!