Skip to main content
Known Participant
Jun 9, 2022 11:39 AM UTC
Solved

Showwhen Activity

can we write both and() and or() conditions in the showwhen activity. i have tried for a text field. if the checkbox is selected the textbox should appear. but it is also appearing in the next page. can anyone pls help

    konduruc733182
    Inspiring
    Jun 9, 2022 12:01 PM UTC

    a!localVariables(
    local!text,
    local!checkbox,
    local!currentstep: 1,
    a!sectionLayout(
    contents: {
    a!textField(
    showWhen: and(local!checkbox="Show field",local!currentstep=1),
    label: "Text field",
    value: local!text,
    saveInto: local!text
    ),
    a!checkboxField(
    choiceLabels: {"Show field"},
    choiceValues: {"Show field"},
    saveInto: local!checkbox,
    value: local!checkbox
    
    ),
    
    }
    )
    )

    If you are using a milestone to display multiple steps, you can use the above condition for showWhen. Hope this will help you with your issue. 

    4 replies

    stewart.burchell
    Employee
    Jun 9, 2022 11:45 AM UTC

    the showWhen takes a Boolean. So as long as your logic returns 'true' or 'false' then it doesn't matter what constructs you use.

    stewart.burchell
    Employee
    Jun 9, 2022 11:56 AM UTC

    As an addendum - I'd strongly encourage you to encapsulate the logic into an Expression rule, separate form the Interface, unless it is only a single value comparison. In this way you can a) independently test it and confirm that it is working as expected and b) you can attach Unit Tests to the rule which means you can provide continual Quality Assurance on the logic as your application evolves. It also makes a clear separation between business logic and presentation which is just good practice.

    konduruc733182
    Inspiring
    Jun 9, 2022 12:01 PM UTC

    a!localVariables(
    local!text,
    local!checkbox,
    local!currentstep: 1,
    a!sectionLayout(
    contents: {
    a!textField(
    showWhen: and(local!checkbox="Show field",local!currentstep=1),
    label: "Text field",
    value: local!text,
    saveInto: local!text
    ),
    a!checkboxField(
    choiceLabels: {"Show field"},
    choiceValues: {"Show field"},
    saveInto: local!checkbox,
    value: local!checkbox
    
    ),
    
    }
    )
    )

    If you are using a milestone to display multiple steps, you can use the above condition for showWhen. Hope this will help you with your issue. 

    neilb2444Author
    Known Participant
    Jun 10, 2022 11:31 AM UTC

    Thanks for the help