Checkbox False Value Not being saved

Hi,

I have checked all the posts for how to capture the values from a checkbox and save it to an output CDT data element, but nothing has worked.

In my form, I have the following checkbox code where the only thing I want to do is if checked the value is true, if not cheched the value is false. I added a local variable (local!reqdoc) to hold the selected value.

                     a!checkboxField(
                        label: "",
                        labelPosition: "ABOVE",
                        choiceLabels: {"Requirements documentation"},
                        choiceValues: {true},
                        value: if(local!reqdoc, true, null),
                        saveInto: a!save(local!reqdoc, if(isnull(save!value), false, true))
                        )

In the Submit button component, I added the following code with a!save()

        a!buttonWidget(
          label: "Submit",
          saveInto: {
            a!save(ri!requests.status, "Submitted"),
            a!save(ri!requests.requirements, local!reqdoc)
          }

If I check the checkbox, it saves as true, however, if the checkbox is not checked the value that is saved is null. 

Can someone help me to fix this?

Thank you,

Roberta

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    I see you had a working solution suggested already, but I figured I would chip in with my experience in case it helps you or anyone else.

    So, the basic fact here is that a!checkboxField() wasn't really made to handle a simple boolean (yes/no) selection at all.  It can be done but it requires a bit of legwork. 

    To deal with this, a few years ago I went ahead and created a "boolean checkbox" interface to serve as a shortcut - the extra legwork is handled internally so that when it's called, you only need to pass in some specific things to get it working:

    1. trueValue: the value you want saved into your target variable when the box is checked
    2. falseValue: the value it should get when the box is un-checked (note: this can be anything, but it will require the user to check and un-check the box to get this value)
    3. value: this is the primary save target, as well as the source of what the checkbox should display (i.e. whether it will appear checked or unchecked).  Initially it should be equal to the value of either trueValue or falseValue (or null). If set to anything other than these choices, the checkbox will also appear unchecked.
    4. checkboxLabel -or- label: i typically leave "label" blank and set "checkboxLabel" to a value which then appears to the right of the checkbox

    /* GLBL_Component_BooleanCheckbox */
    a!checkboxField(
      label: ri!label,
      choiceLabels: { ri!checkboxLabel },
      choiceValues: { ri!trueValue },
      value: if(
        ri!value = ri!trueValue,
        ri!value,
        null()
      ),
      saveInto: {
        a!save(
          ri!value,
          if(isnull(save!value), ri!falseValue, ri!trueValue)
        )
      },
      
      /* optional standard parameters: */
      labelPosition: ri!labelPosition,
      instructions: ri!instructions,
      helpTooltip: ri!helpTooltip,
      required: ri!required,
      requiredMessage: ri!requiredMessage,
      accessibilityText: ri!accessibilityText,
      disabled: ri!readOnly,
      validations: ri!validations,
      align: ri!align,
      showWhen: ri!showWhen
    )

    All the other rule inputs are optional, and just allow the component to act more like the regular checkboxField when desired (labelPosition, instructions, validations, etc.)

Reply
  • 0
    Certified Lead Developer

    I see you had a working solution suggested already, but I figured I would chip in with my experience in case it helps you or anyone else.

    So, the basic fact here is that a!checkboxField() wasn't really made to handle a simple boolean (yes/no) selection at all.  It can be done but it requires a bit of legwork. 

    To deal with this, a few years ago I went ahead and created a "boolean checkbox" interface to serve as a shortcut - the extra legwork is handled internally so that when it's called, you only need to pass in some specific things to get it working:

    1. trueValue: the value you want saved into your target variable when the box is checked
    2. falseValue: the value it should get when the box is un-checked (note: this can be anything, but it will require the user to check and un-check the box to get this value)
    3. value: this is the primary save target, as well as the source of what the checkbox should display (i.e. whether it will appear checked or unchecked).  Initially it should be equal to the value of either trueValue or falseValue (or null). If set to anything other than these choices, the checkbox will also appear unchecked.
    4. checkboxLabel -or- label: i typically leave "label" blank and set "checkboxLabel" to a value which then appears to the right of the checkbox

    /* GLBL_Component_BooleanCheckbox */
    a!checkboxField(
      label: ri!label,
      choiceLabels: { ri!checkboxLabel },
      choiceValues: { ri!trueValue },
      value: if(
        ri!value = ri!trueValue,
        ri!value,
        null()
      ),
      saveInto: {
        a!save(
          ri!value,
          if(isnull(save!value), ri!falseValue, ri!trueValue)
        )
      },
      
      /* optional standard parameters: */
      labelPosition: ri!labelPosition,
      instructions: ri!instructions,
      helpTooltip: ri!helpTooltip,
      required: ri!required,
      requiredMessage: ri!requiredMessage,
      accessibilityText: ri!accessibilityText,
      disabled: ri!readOnly,
      validations: ri!validations,
      align: ri!align,
      showWhen: ri!showWhen
    )

    All the other rule inputs are optional, and just allow the component to act more like the regular checkboxField when desired (labelPosition, instructions, validations, etc.)

Children
No Data