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
  • Hi Roberta,

    The reason is because only exists the value true in your check box, (choiceValues: {true},) if you want to save a true/false I recommended you to use a radio button

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

    or change de save to allow to save a null 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), null, true))
    ),

    I hope the information is helpful

    Regards

Reply
  • Hi Roberta,

    The reason is because only exists the value true in your check box, (choiceValues: {true},) if you want to save a true/false I recommended you to use a radio button

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

    or change de save to allow to save a null 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), null, true))
    ),

    I hope the information is helpful

    Regards

Children