Skip to main content
August 12, 2022
Solved

Disable button.

  • August 12, 2022
  • 8 replies
  • 0 views

I have 3 buttons and two buttons must to be disabled if I select one of the 3 butttons.

I tried with the follow code on disabled property:

a!buttonArrayLayout(
     buttons: {
          a!buttonWidget(
               icon: "check",
               size: "LARGE",
               value: local!buttonVal = 2,
               style: "DESTRUCTIVE",
               disabled: if(local!buttonselected = true, if(local!buttonVal = 1, "SECONDARY", false), false),
               submit: a!save(local!buttonselected, true)
)
},
      align: "CENTER"
)

    Best answer by deepakg681722

    a!localVariables(
      local!btnSelected,
      {
        a!buttonArrayLayout(
          buttons: {
            a!buttonWidget(
              icon: "check",
              size: "LARGE",
              style: "DESTRUCTIVE",
              saveInto: { a!save(local!btnSelected, 1) },
              disabled: contains({ 2, 3 }, tointeger(local!btnSelected))
            ),
            a!buttonWidget(
              icon: "check",
              size: "LARGE",
              style: "DESTRUCTIVE",
              saveInto: { a!save(local!btnSelected, 2) },
              disabled: contains({ 1, 3 }, tointeger(local!btnSelected))
            ),
            a!buttonWidget(
              icon: "check",
              size: "LARGE",
              style: "DESTRUCTIVE",
              saveInto: { a!save(local!btnSelected, 3) },
              disabled: contains({ 2, 1 }, tointeger(local!btnSelected))
            )
          },
          align: "CENTER"
        )
      }
    )

    Please try this code. I save the value for each button as 1,2 and 3 and according to these values i set the disability logic for the buttons.

    8 replies

    gopalk2865
    Participating Frequently
    August 13, 2022

    Hi, you would need to save values on click of each button, you can use local variables to save your values. And the use this local variables to configure disable parameter of each button.

    stefanhelzle0001
    Brainy
    August 14, 2022

    The way you use the logic for the disabled parameter seems to be OK. Where and how do you modify the two locals? This should be part of the saveInto of the dropdown.

    August 15, 2022

    a!localVariables(
      local!buttonVal:0,
      local!btnSelected: true,
      {
        a!boxLayout(
          label: "Tu Escudo",
          contents: {
            a!columnsLayout(
              columns: {
                a!columnLayout(
                  contents: {
                    a!cardLayout(
                      contents: {
                        a!cardLayout(
                          contents: {
                            a!richTextDisplayField(
                              labelPosition: "COLLAPSED",
                              value: {
                                a!richTextHeader(
                                  text: {
                                    "Enfermedades Frecuentes"
                                  }
                                )
                              },
                              align: "CENTER"
                            )
                          },
                          height: "AUTO",
                          style: "NONE",
                          marginBelow: "STANDARD",
                          showBorder: false
                        )
                      },
                      height: "AUTO",
                      style: "NONE",
                      marginBelow: "STANDARD",
                      showBorder: false
                    )
                  }
                ),
                a!columnLayout(
                  contents: {
                    a!sectionLayout(),
                    a!dropdownField(
                      label: "Plan Dental",
                      labelPosition: "COLLAPSED",
                      placeholder: "$10,000.00",
                      choiceLabels: {"Option 1", "Option 2", "Option 3", "Option 4",
                      "Option 5", "Option 6", "Option 7", "Option 8",
                      "Option 9", "Option 10", "Option 11", "Option 12"},
                      choiceValues: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12},
                      saveInto: {},
                      searchDisplay: "AUTO",
                      validations: {}
                    )
                  }
                ),
                a!columnLayout(
                  contents: {
                    a!cardLayout(
                      contents: {
                        a!columnsLayout(
                          columns: {
                            a!columnLayout(
                              contents: {
                                a!buttonArrayLayout(
                                  buttons: {
                                    a!buttonWidget(
                                      icon: "check",
                                      size: "LARGE",
                                      style: "DESTRUCTIVE",
                                      saveInto: { a!save(local!btnSelected, 1) },
                                      disabled: contains({ 2, 3 }, tointeger(local!btnSelected))
                                    )
                                  },
                                  align: "CENTER"
                                )

    I have the follow code using [mention:6a17174541734ea98f60de800dbbac95:e9ed411860ed4f2ba0265705b8793d05] solution-

    August 15, 2022

    a!localVariables(
      local!btnSelected,
      {
        a!buttonArrayLayout(
          buttons: {
            a!buttonWidget(
              icon: "check",
              size: "LARGE",
              style: "DESTRUCTIVE",
              saveInto: { a!save(local!btnSelected, 1) },
              disabled: contains({ 2, 3 }, tointeger(local!btnSelected))
            ),
            a!buttonWidget(
              icon: "check",
              size: "LARGE",
              style: "DESTRUCTIVE",
              saveInto: { a!save(local!btnSelected, 2) },
              disabled: contains({ 1, 3 }, tointeger(local!btnSelected))
            ),
            a!buttonWidget(
              icon: "check",
              size: "LARGE",
              style: "DESTRUCTIVE",
              saveInto: { a!save(local!btnSelected, 3) },
              disabled: contains({ 2, 1 }, tointeger(local!btnSelected))
            )
          },
          align: "CENTER"
        )
      }
    )

    Please try this code. I save the value for each button as 1,2 and 3 and according to these values i set the disability logic for the buttons.

    August 15, 2022

    It works, but just disabled the button number one and it doesn't let me choose another one.

    The 3 buttons must be enabled.

    August 15, 2022

    I made a few changes on the code, I created 7 local variables because I have 24 buttons and every row is different

    Thank you a lot,