Need to put shown condition in Button

Hi All,

I'm having a button "COMPLETE"

i want to put a shown condition on it in the following basis


I'm having an array {"Completed","Not Completed"},

If both the values in that array are in completed status then only i want to show that button.

Could you please help me with the logic.

Thanks

  Discussion posts and replies are publicly visible

  • This is done utilizing the "showWhen" parameter.  This example assumes your array always contains 2 values, as noted in the original post, and includes dropdowns for you to change the array values to see it in action.

    Note that often instead of using the "showWhen" parameter to hide the button, I often use the "disabled" parameter so users know it exists, but does not let them press it until the desired values are present.  Comment out the showWhen code to see how that functionality works.

    a!localVariables(
      local!data: {"Completed","Not Completed"},
      
      {
        a!columnsLayout(
          columns: {
            a!columnLayout(
              contents: {
                a!dropdownField(
                  label: "Data 2",
                  labelPosition: "ADJACENT",
                  choiceLabels: {"Completed","Not Completed"},
                  choiceValues: {"Completed","Not Completed"},
                  value: local!data[1],
                  saveInto: local!data[1]
                )
              }
            ),
            a!columnLayout(
              contents: {
                a!dropdownField(
                  label: "Data 2",
                  labelPosition: "ADJACENT",
                  choiceLabels: {"Completed","Not Completed"},
                  choiceValues: {"Completed","Not Completed"},
                  value: local!data[2],
                  saveInto: local!data[2]
                )
              }
            )
          }
        ),
        a!buttonArrayLayout(
          align: "CENTER",
          buttons: a!buttonWidget(
            label: "COMPLETE",
            showWhen: and(
              index(local!data,1,null)="Completed",
              index(local!data,2,null)="Completed"
            ),
            disabled: or(
              index(local!data,1,null)<>"Completed",
              index(local!data,2,null)<>"Completed"
            )
          )
        )
      }
    )

  • Thank you Chris,

    But my array won't contain only 2 values always, they may increase the count of values but those are only Completed or not completed.

    If I can say clearly, if I'm having at least one value as not completed then my button should be disabled.

    Hope I explained in a clear way?

    Scenario's like:

    {"Completed","Completed","Completed","Completed","Completed","Not Completed"} ---->Button Should be Disabled

    {"Completed","Completed","Completed","Completed","Completed","Completed"} ---->Button Should be Enable

    like so on..

  • Yes, no problem there.  This second example works for a dynamically sized array - using the wherecontains() function searching for Completed values, we check how many instances are found against the total count of items in the array:

    a!localVariables(
      local!data: {"Completed","Not Completed","Completed"},
      /*local!data: {"Completed","Completed","Completed"},*/
    
      {
        a!buttonArrayLayout(
          align: "CENTER",
          buttons: a!buttonWidget(
            label: "COMPLETE",
            showWhen: count(wherecontains("Completed",local!data))=count(local!data)
          )
        )
      }
    )

  • Quick update using "disabled" vs "showWhen" (I prefer "disabled").  Change the commenting on local!data lines and re-test to see it activate:

    a!localVariables(
      local!data: {"Completed","Not Completed","Completed"},
      /*local!data: {"Completed","Completed","Completed"},*/
    
      {
        a!buttonArrayLayout(
          align: "CENTER",
          buttons: a!buttonWidget(
            label: "COMPLETE",
            disabled: not(
              count(wherecontains("Completed",local!data))=count(local!data)
            )
          )
        )
      }
    )

  • 0
    Certified Lead Developer
    in reply to Harris

    Another option using looping functions:

    a!localVariables(
      local!allCompleted: {"Completed","Completed","Completed"},
      local!someOpen: {"Completed","Not Completed","Completed"},
      {
        assertTrue: all(exact("Completed", _), local!allCompleted),
        assertFalse: all(exact("Completed", _), local!someOpen),
      }
    )