APIs & Integrations

Zonal
Participant

Stop showing error message when using JavaScript to change field value to empty - is this possible?

I have a contact form embedded on a wordpress site that has several fields on it that I want to pre-populate (name, email, company etc), but also a "message" field that I want to load empty each time as each form submission have a new message.

I have set the form to prepopulate, then am using JS to change the value of this one field:

$('textarea[name="message"]').val('').change();

This works and the form loads empty, however as the field has been "edited", the default bevaviour on mobile seems to be to display the "Please complete this required field" error message. (note: this also happens on desktop if I click the "not you" link to reset the form).

This would be expected behaviour if a user edited a required field and left it blank, but it is not the desired behaviour when the field value is change via code like this.

Is there any javascript that can be used (or any other method) that can change the text of the field to empty but not display this error mesage?

0 Upvotes
1 Reply 1
WendyGoh
HubSpot Employee
HubSpot Employee

Stop showing error message when using JavaScript to change field value to empty - is this possible?

Hey @Zonal,

 

How are you executing the callback  function of the form embed code?

 

Additionally, could you also share with me the following:

1. The page that has the form

2. Portal ID

3. Form ID

 

So that I can do some test on my end.

0 Upvotes