Skip to main content
Question

Advanced prototyping with variants that change state using variables

  • July 8, 2024
  • 1 reply
  • 183 views

Hi everyone,

I’m having trouble with something in Figma and could really use some assistance.

I’ve designed a mobile questionnaire and set up variables to enable the “Next” button only when an answer is selected. By default, the footer containing the “Next” and “Back” buttons is disabled.

My issue is that I can’t figure out how to prototype the transition from one question to the next if the “Next” button is disabled in my frame by default. I know there are workarounds using multiple frames, but that gets really tedious. I also know I could use the base component and make the transition from there, but the “Next” button doesn’t always lead to the same page, just the next question.

As a new user, I can’t add a video, so I hope this makes sense.

Any advice or guidance on how to achieve this would be greatly appreciated!

Thank you!

This topic has been closed for comments

1 reply

Bauke_Schildt

Let’s say that when the user clicks an answer you:

  • Set variable “ButtonNextState” to “Enabled” (Or whatever your component variant name for that state is)
    And
  • Set variable “AnswerClicked” to “True”

You can use a Conditional (Or “Check If/Else” in UI3) on your button instance. (Not in your Component):

On click
**If** "AnswerClicked" == True
Navigate to [Question 2]

You can leave the Else empty, in which case the button does nothing, or you can use it to trigger a message like “Please select an answer”

As the interaction is on the instance, Figma doesn’t care which variant of the instance you’re showing.

If you need to do 2 checks, for example you want the user to go to a “fail” page when they get 3 questions wrong:
When they click the (wrong) answer:

  • Set Variable “WrongAnswers” == “WrongAnswers” + 1

and on the “Next” button:

On click
**If** "AnswerClicked" == True AND "WrongAnswers" < 3 //(less than 3)
Navigate to [Question 2]
**Else**
Navigate to [Fail]

On the next page you can reset the variable for “AnswerClicked” to “False” with the “After Delay” option on the frame and setting it to 1ms. (We really need a “On load” option for this, but this workaround works for now)


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings