Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

How to deactivate parts of the formular based on previous answers?

Avatar

Level 1

Hi Guys,

i have the following problem:

My goal is to a set up a formular of the following form:

Question 1:

A:  Blabalbalab

B: Blabalbalbabla

If you choose A then continue with Question 2, if you choose B then continue with question 3.

So in case the user chooses B question 2 should be skipped. I seek a way that the fields of question 2 will be automatically deactivated when the user chooses B in question 1. Basically by pressing tab the user should directly be directed to question 3 if he has choosen B in question 1.

This should be possible, right?

Anyone, who knows how to do that?

Greetings,

Andreas

2 Replies

Avatar

Level 7

Hi,

You can do this easily by changing the access event for the radio buttons. I would use a table to make it easier to 'disable' a question based on the answer.

This is my result:

1302975_pastedImage_0.png

When Answer B is clicked, Question 2 is 'disabled'.

You can see below that i have set mine up with one question and answer radio buttons per row. By using a table, you can just 'disable the whole row rather than having to disable multiple items.

1302976_pastedImage_1.png

In the Q1 Answer B click event add this:

form1.#subform[0].Table1.Row1.#subform[0].RadioButtonList.#field[1]::click - (JavaScript, client) //Q1 Answer B

this.resolveNode("Row2").access = "protected"; //using protected rather than read only ensures that TAB skips the field when pressed.

Make sure you add the opposite to Q1 Answer A. If the user changes their mind, you need to re-enable Q2

form1.#subform[0].Table1.Row1.#subform[0].RadioButtonList.#field[0]::click - (JavaScript, client) //Q1 Answer A

this.resolveNode("Row2").access = "open"; //open enables the row again

The code does not send focus to Q3 when a selection is made because pressing tab will do that for you.

Avatar

Level 7

do you want to protect the question if it is skipped or push the user to the appropriate question? This is a conditional response. We see this on paper forms all the time for example: if you selected "no children" skip question 3 and go to question 9. If this is the case you may want to not only lock the subsequent questions (as they are not relevant) but drive the user to the next question they need to respond to. as MinusZero has indicated you can lock the questions however once that is done, you would want to set the focus to the next question. You would need to use the setFocus function in your script xfa.host.setFocus("#field"); for example