Skip to main content
June 9, 2022
Solved

Showwhen Activity

  • June 9, 2022
  • 4 replies
  • 0 views

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

    Best answer by konduruc733182

    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
    June 9, 2022

    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
    June 9, 2022

    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
    June 9, 2022

    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
    June 10, 2022

    Thanks for the help