CMS Development

AirswiftRob
Contributor

Looking for a way to dynamically change the Label Text on a HubSpot Form

SOLVE

Hi,

 

We are using the API from another system to create HubDB records and dynamic pages. We are then using one form (a job application form) on all dynamic pages to track registrations.

 

On the form, we would like to change the question text for certain HubDB records if a custom screening question has been added in the other system.

For example

 

HubDB RecordOther System IDCustom Screening Question
0010067Do you like Apples?
002071Do you like Oranges
003087 

 

In records 001 & 002, I want the custom screening property label to display a question relating to apples or oranges respectively. For example 003. I do not want the question to appear at all because the field is blank.

Is this possible? 

0 Upvotes
1 Accepted solution
Teun
Solution
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

Looking for a way to dynamically change the Label Text on a HubSpot Form

SOLVE

Hi @AirswiftRob ,

 

Yes, this is possible. I would create custom inputs with HubL  You can use HubL combined with if else statements to display a certain question. If you display your HubSpot form below those custom inputs you can use some JavaScript to add an event listener to the custom inputs and update a hidden field in the HubSpot form.

 

const customInput = document.getElementById('custom-input') 
const hiddenInput = document.querySelector('input[name="hidden_input"]');

customInput.addEventListener('change', e => {
  hiddenInput.value = customInput.value;
  hiddenInput.dispatchEvent(new Event('input', { bubbles: true }));
})

 



Did my answer solve your issue? Help the community by marking it as the solution.

View solution in original post

2 Replies 2
AirswiftRob
Contributor

Looking for a way to dynamically change the Label Text on a HubSpot Form

SOLVE

Thank you @Teun I will try this out and report back

 

0 Upvotes
Teun
Solution
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

Looking for a way to dynamically change the Label Text on a HubSpot Form

SOLVE

Hi @AirswiftRob ,

 

Yes, this is possible. I would create custom inputs with HubL  You can use HubL combined with if else statements to display a certain question. If you display your HubSpot form below those custom inputs you can use some JavaScript to add an event listener to the custom inputs and update a hidden field in the HubSpot form.

 

const customInput = document.getElementById('custom-input') 
const hiddenInput = document.querySelector('input[name="hidden_input"]');

customInput.addEventListener('change', e => {
  hiddenInput.value = customInput.value;
  hiddenInput.dispatchEvent(new Event('input', { bubbles: true }));
})

 



Did my answer solve your issue? Help the community by marking it as the solution.