Validation code that 'Next' button is pressed | XM Community
Skip to main content
Solved

Validation code that 'Next' button is pressed


Forum|alt.badge.img+2

Hi.

I would like to insert code to validate the values of the UI on the page when the Next button is pressed. Could you please provide some advice?

Best answer by TomG

@norikazukuriiwa,

Rather than setting embedded data fields when Interface03 or Interface04 are selected, you should make Interface03 and Interface04 text entry questions with the text entry hidden. When the dropdowns are selected, set the value of the associated text entry. Do validation based on whether the text entry values not empty.  

View original

10 replies

  • Level 4 ●●●●
  • 212 replies
  • February 17, 2025

Depends on what kind of validation you are looking for and which question type do you use.


Forum|alt.badge.img+2

Dear jbk

Sorry for late responding.

Below is the portion of the survey I created.

Description of Each Interface

 Interface01: A text box for entering the First Name, not subject to validation.

 Interface02: A text box for entering the Family Name, not subject to validation.

 Interface03: A drop-down list for setting the country name by referencing a table in an external database via API, subject to validation.

 Interface04: A drop-down list for setting the company name associated with the country selected in Interface03, subject to validation.

 Interface05: A text box for entering the company name if it is not displayed in Interface04, subject to validation.

 Interface06: A text box for entering the department name, not subject to validation.

 Interface07: A text box for entering the phone number, subject to validation.

 Interface08: A text box for entering an additional phone number, subject to validation.

 Interface09,10: Text boxes for entering the email address, subject to validation.


About Validation

The validation content changes depending on the selection of the radio button.

  • When Yes:
    • No validation is performed.
  • When No:
    • The following validations are performed:
      • Interface03 is not null.
      • Either Interface04 or Interface05 is not null.
      • Interface07 is not null.
      • Interface08 is not null.
      • Interface09 and Interface10 are not null and have the same value.

Issues

Interface03 and Interface04 cannot be set from the GUI validation. Is it because they reference data via API?
 


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5938 replies
  • February 18, 2025

What type of Qualtrics questions are Interface03 and Interface04? (e.g., multiple choice, text entry, etc.)


Forum|alt.badge.img+2

>What type of Qualtrics questions are Interface03 and Interface04?

They’re single choice dropdowns.

 

Also, each value is set to embedded data using Qualtrics.SurveyEngine.setEmbeddedData.


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5938 replies
  • February 19, 2025
norikazukuriiwa wrote:

>What type of Qualtrics questions are Interface03 and Interface04?

They’re single choice dropdowns.

Also, each value is set to embedded data using Qualtrics.SurveyEngine.setEmbeddedData.

I’m still confused. What exactly do you mean by “by referencing a table in an external database via API” because you can’t dynamically create choices in a Qualtrics multiple choice question.


Forum|alt.badge.img+2
  • We Developed an API to import data into Interface03 and Interface04 from an external database.
  • When the user clicks on Interface03, country data is referenced and imported via the API, and the user selects one country from the displayed list. Immediately after selection, the selected value is set using embedded data.
  • When the user clicks on Interface04, company name data under the country set in Interface03 is referenced and imported via the API, and the user selects one company name from the displayed list. Immediately after selection, the selected value is set using embedded data.
  • Although I am aware of the option to import choices using the choice group function, Interface04 involves thousands of items, making it impossible to import all the information. Therefore, data is referenced via the API and imported into the dropdown.
  • The reason for using EmbeddedData is that the values set in Interface03 and Interface04 disappear when the Next button is pressed.

Does this clarify things for you?


Forum|alt.badge.img+2
  • The reason for wanting to perform validation when the Next button is pressed is that the values set in interface03 and interface04 are cleared when the Next button is pressed, making validation impossible. Instead, I want to validate whether the values are entered into Embedded Data for interface03 and interface04.
  • If the above issue can be resolved, the validation of other interfaces can be substituted with the GUI validation function. However, I would prefer to implement all validations in code to enhance maintainability.

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5938 replies
  • Answer
  • February 20, 2025

@norikazukuriiwa,

Rather than setting embedded data fields when Interface03 or Interface04 are selected, you should make Interface03 and Interface04 text entry questions with the text entry hidden. When the dropdowns are selected, set the value of the associated text entry. Do validation based on whether the text entry values not empty.  


Forum|alt.badge.img+2

Dear TomG

I have tried the method you advised in the past, but I am writing here to see if there is a better way. Thank you.


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5938 replies
  • February 21, 2025
norikazukuriiwa wrote:

Dear TomG

I have tried the method you advised in the past, but I am writing here to see if there is a better way. Thank you.

A better way, no. More difficult ways, yes.


Leave a Reply